Jump to content
Sign in to follow this  
Ices

Issues with FTP.exe

Recommended Posts

Ices

Okay, im having an issue with FTP.exe. with my program, I can get it to connect to my FTP server, log in, and disconnect, but when I try to have it send a file, it doesnt do anything. Ive tried the send command and the put command. It doesnt give me an error code, it doesnt say that its trying to send, it doesnt do anything. Any ideas anyone?

Share this post


Link to post
Share on other sites
buzz44

Okay, im having an issue with FTP.exe. with my program, I can get it to connect to my FTP server, log in, and disconnect, but when I try to have it send a file, it doesnt do anything. Ive tried the send command and the put command. It doesnt give me an error code, it doesnt say that its trying to send, it doesnt do anything. Any ideas anyone?

<{POST_SNAPBACK}>

is this for autoit or just ftp, if not i suggest using an FTP Client such as FTP Commander or one of the many others

qq

Share this post


Link to post
Share on other sites
Ices

is this for autoit or just ftp, if not i suggest using an FTP Client such as FTP Commander or one of the many others

<{POST_SNAPBACK}>

My issue is that this program is going to be self contained, and it cant use anything but what windows comes with, ie ftp.exe. So unless I write an entire FTP program into my script, using something else is a no go :-/

Share this post


Link to post
Share on other sites
buzz44

My issue is that this program is going to be self contained, and it cant use anything but what windows comes with, ie ftp.exe. So unless I write an entire FTP program into my script, using something else is a no go :-/

<{POST_SNAPBACK}>

well im not that familiar with ftp, as i couldnt even figure out how to set a server up lol, are you sure u are typing in the syntax correctly, do u have to open the server first?

qq

Share this post


Link to post
Share on other sites
batfastad

Hi Ices,

I've got a script that does an automatic FTP every 24 hours and it uses window's built in ftp.exe with great success.

One suggestion though...

I first had the script send keystrokes to the window of ftp.exe, then wait 10 seconds, then send the next command.

The 10 seconds wait was meant to delay the sending of keystrokes in case network conditions meant delays in response from the server.

That was a stupid idea!!!

The best way to do it is this...

Windows' ftp.exe has a very useful feature which lets you create a file of batch commands and you can run that file by using the -s switch...

So in a command window in windows instead of typing

ftp.exe

you would go...

ftp.exe -s:C:\my_ftp_batch_script.txt

Or whatever the path to your batch text file is.

Set up a text file containing all the commands you want to send to the server, each on a separate line (modify the code below for your own details).

open
ftp.domain.net
my_username
my_password
cd testfolder
cd subfolder
hash
binary
send
C:\test.file
test.file
close
bye

Save it as ftp.txt or something.

Then in your AutoIt script...

Run ("ftp -s:C:\ftp.txt")

ftp.exe then executes each line of ftp.txt once it is ready to accept the command. So once there's a ftp> prompt there.

So if ftp.exe is busy performing a command, it won't rush through the rest of the batch script and close/quit.

When automating ftp transfers I always use the hash command when using ftp.exe as it gives you some (limited) feedback of how the transfer's going - useful if you're moving a 30MB file!!

Also the line where it says binary - don't forget to delete that line if you're sending a text based file (HTML, PHP, CSS).

That above ftp.txt connects, navigates to a certain directory sends the file 'test.file', and closes the connection and exits ftp.exe once the transfer is complete.

I've managed to accomplish some clever stuff using batch commands and ftp.exe with AutoIt.

If you want to compile the script then what I've done is include the ftp.txt and ftp.exe files into the compiles autoit .exe file, then used the Install() function in my AutoIt script to extract them to a temp directory while the script is running, then delete the temp directory once it's done.

When packing ftp.exe inside your compiled script watch out...

It's microsoft software so you can't distribute (I assume!)

Different windows versions 9x may have different versions to XP

Be warned though, anyone can peek inside your ftp.txt file and find the username/password to your FTP server.

HTH

Batfastad

Edited by batfastad

Share this post


Link to post
Share on other sites
Ices

well im not that familiar with ftp, as i couldnt even figure out how to set a server up lol, are you sure u are typing in the syntax correctly, do u have to open the server first?

<{POST_SNAPBACK}>

Heres what im doing. Im using FTP.exe to upload files to an FTP server. Its possible that the server isnt set up correctly to accept uploads, but I doubt it. when the FTP function in my program is triggered, it opens up a command line, connects to the ftp, logs in, and is supposed to upload a file, but I cant figure that part out.

This is the line of code used to send the command to send the file

ControlSendPlus("C:\WINDOWS\system32\ftp.exe", "", "", "send " & @ScriptDir & "\" & $file & "{enter}", 0)

Share this post


Link to post
Share on other sites
buzz44

Heres what im doing. Im using FTP.exe to upload files to an FTP server. Its possible that the server isnt set up correctly to accept uploads, but I doubt it. when the FTP function in my program is triggered, it opens up a command line, connects to the ftp, logs in, and is supposed to upload a file, but I cant figure that part out.

This is the line of code used to send the command to send the file

ControlSendPlus("C:\WINDOWS\system32\ftp.exe", "", "", "send " & @ScriptDir & "\" & $file & "{enter}", 0)

<{POST_SNAPBACK}>

have u tried using batfastad's script above?, u might want to use.

#include <Process.au3>

_RunDos("ftp" & "{enter}" & "send " & @ScriptDir & "\" & $file & "{enter}", 0)
Edited by burrup

qq

Share this post


Link to post
Share on other sites
Ices

have u tried using batfastad's script above?, u might want to use.

#include <Process.au3>

_RunDos("ftp" & "{enter}" & "send " & @ScriptDir & "\" & $file & "{enter}", 0)

<{POST_SNAPBACK}>

I figured out my issue, but with solving one problem, another comes up. The reason it wasnt sending, is because ftp.exe doesnt accept long filenames, any directory names with spaces, it doesnt work. So what I need to know now, is to know how to convert @ScriptDir to short filenames? Any Ideas?

Share this post


Link to post
Share on other sites
buzz44

I figured out my issue, but with solving one problem, another comes up. The reason it wasnt sending, is because ftp.exe doesnt accept long filenames, any directory names with spaces, it doesnt work. So what I need to know now, is to know how to convert @ScriptDir to short filenames? Any Ideas?

<{POST_SNAPBACK}>

why note just move the file you want to send to another directory eg, c:\temp\"file", instead of having it in the same place as your script?, is that what longfile names mean lol?

qq

Share this post


Link to post
Share on other sites
batfastad

Hi

So I assume you've opened up the ftp.exe connection somewhere earlier in your script?

If you have then I can see why you've tried it that way.

But i would suggest you try it the way I detailed above.

Use autoit to start ftp.exe with the batch script option.

Then in your batch script you will have no trouble with the send command.

Another tip... with AutoIt don't forget you can create text files on the fly.

So if you need to use certain variables in your ftp batch script you can have AutoIt write the ftp.txt batch file, then run ftp.exe with that batch file, then delete the batch file once it's finished.

If you do go down the batch route - then you'll need to pause your autoit script until the ftp commands have finished. Don't forget you'll need to add the close and bye FTP commands to your batch script.

To pause your AutoIt script until the FTP batch file has finished...

WinWaitClose ("ftp.exe")

One suggestion with your method...

Though one thing to check with the way you're doing it at the moment is to try this at the top of your script...

AutoItSetOption ("WinTitleMatchMode",2)

Then in your ControlSendPlus function...

ControlSendPlus("ftp.exe",

Change it so that AutoIt tries to find a window title containing the string ftp.exe and not C:\WINDOWS\system32\ftp.exe

It may be that AutoIt is not typing the command into the correct window.

I normally put a Sleep (500) or something before doing something like that.

Just for your information - when I do...

Run ("ftp.exe -s:C:\ftpbatch.txt")

The window title it just ftp.exe - not C:\WINDOWS\system32\ftp.exe

So maybe autoit isn't finding the ftp.exe window.

I doubt it but without more info of your current script it's all that comes to mind.

Let us know how it turns out - at least give the batch method a go. It's a very powerful feature!

Thanks

Batfastad

Share this post


Link to post
Share on other sites
Ices

Hi

So I assume you've opened up the ftp.exe connection somewhere earlier in your script?

If you have then I can see why you've tried it that way.

But i would suggest you try it the way I detailed above.

Use autoit to start ftp.exe with the batch script option.

Then in your batch script you will have no trouble with the send command.

Another tip... with AutoIt don't forget you can create text files on the fly.

So if you need to use certain variables in your ftp batch script you can have AutoIt write the ftp.txt batch file, then run ftp.exe with that batch file, then delete the batch file once it's finished.

If you do go down the batch route - then you'll need to pause your autoit script until the ftp commands have finished. Don't forget you'll need to add the close and bye FTP commands to your batch script.

To pause your AutoIt script until the FTP batch file has finished...

WinWaitClose ("ftp.exe")

One suggestion with your method...

Though one thing to check with the way you're doing it at the moment is to try this at the top of your script...

AutoItSetOption ("WinTitleMatchMode",2)

Then in your ControlSendPlus function...

ControlSendPlus("ftp.exe",

Change it so that AutoIt tries to find a window title containing the string ftp.exe and not C:\WINDOWS\system32\ftp.exe

It may be that AutoIt is not typing the command into the correct window.

I normally put a Sleep (500) or something before doing something like that.

Just for your information - when I do...

Run ("ftp.exe -s:C:\ftpbatch.txt")

The window title it just ftp.exe - not C:\WINDOWS\system32\ftp.exe

So maybe autoit isn't finding the ftp.exe window.

I doubt it but without more info of your current script it's all that comes to mind.

Let us know how it turns out - at least give the batch method a go. It's a very powerful feature!

Thanks

Batfastad

<{POST_SNAPBACK}>

my problem with the batch file thing is that there wont be that batch file on the computers running this program. Just the compiled script. my issue isnt actually sending the commands, its that the command wont register if there are any spaces in the directory name when using @ScriptDir. So my issue now is converting @ScriptDir from long filenames to short filenames. Anyone know how to do this?

Share this post


Link to post
Share on other sites
batfastad

Dammit I'm too slow at replying...

I've found that ftp.exe does use long filenames!!

But not spaces.

Spaces don't work with start>run or in a cmd box

To get them to work you need to enclose the string with " speech marks.

Obviously this gets confusing if you're doing it in AutoIt...

function ("string""""","","")

I get confused with how many " to put within my strings!

Try wrapping the entire line with spaces in " - obviously the string will already be in " anyway but you'll have to try it with different numbers of " to get it right.

AutoIt may throw up errors when it tries to run - which is useful as you can then work out where you need to put another one.

HTH

Batfastad

Share this post


Link to post
Share on other sites
Ices

Dammit I'm too slow at replying...

I've found that ftp.exe does use long filenames!!

But not spaces.

Spaces don't work with start>run or in a cmd box

To get them to work you need to enclose the string with " speech marks.

Obviously this gets confusing if you're doing it in AutoIt...

function ("string""""","","")

I get confused with how many " to put within my strings!

Try wrapping the entire line with spaces in " - obviously the string will already be in " anyway but you'll have to try it with different numbers of " to get it right.

AutoIt may throw up errors when it tries to run - which is useful as you can then work out where you need to put another one.

HTH

Batfastad

<{POST_SNAPBACK}>

What happens when @ScriptDir is "C:\documents and settings" what do I do then?

Share this post


Link to post
Share on other sites
buzz44

What happens when @ScriptDir is "C:\documents and settings" what do I do then?

<{POST_SNAPBACK}>

why dont you just move the script into a file that doesnt use spaces eg. c:\temp\

qq

Share this post


Link to post
Share on other sites
buzz44

hey, didnt even realise we had this fucntion

FileGetShortName ( "file" )

Example

$a = FileGetShortName("C:\Program Files")
;$a is probably "C:\PROGRA~1"

that should solve problem :idiot:


qq

Share this post


Link to post
Share on other sites
SumTingWong

Why use FTP.EXE when you can do this:

; Access types for InternetOpen()
Global $INTERNET_OPEN_TYPE_PRECONFIG = 0
Global $INTERNET_OPEN_TYPE_DIRECT = 1
Global $INTERNET_OPEN_TYPE_PROXY = 3
Global $INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4

; Service types for InternetConnect()
Global $INTERNET_SERVICE_FTP = 1
Global $INTERNET_SERVICE_GOPHER = 2
Global $INTERNET_SERVICE_HTTP = 3

Global $INTERNET_DEFAULT_FTP_PORT = 21

Global $INTERNET_FLAG_ASYNC = 0x10000000
Global $INTERNET_FLAG_PASSIVE = 0x08000000

Global $FTP_TRANSFER_TYPE_UNKNOWN = 0x00000000
Global $FTP_TRANSFER_TYPE_ASCII = 0x00000001
Global $FTP_TRANSFER_TYPE_BINARY = 0x00000002

Dim $nRetCode

; Example
$nRetCode = _FtpPutFile("Your ftp server", _
                        "your ftp user name", _
                        "your ftp password", _
                        "c:\some local file.txt", _
                        "remote directory\some local file.txt", _
                        $FTP_TRANSFER_TYPE_ASCII)
MsgBox(4096,'debug line ~23' , '$nRetCode:' & @lf & $nRetCode);### Debug MSGBOX

Func _FtpPutFile($sServer, $sUserName, $sPassword, $sLocalFile, $sRemoteFile, $nType = 0, $nPassive = 1)
   Local $hWininet
   Local $hInternet
   Local $hConnect
   Local $aDllRet
   Local $nRet = 0
   
   $hWininet = DllOpen("wininet.dll")
   If $hWininet = -1 Then Return $nRet
   $aDllRet = DllCall($hWininet, "ptr", "InternetOpen", _
                      "str", "AutoITFTPUDF", _
                      "long", $INTERNET_OPEN_TYPE_DIRECT, _
                      "int", 0, _
                      "int", 0, _
                      "long", $INTERNET_FLAG_ASYNC)
   If Not @error And $aDllRet[0] <> 0 Then
      $hInternet = $aDllRet[0]
      If $nPassive Then
         $nPassive = $INTERNET_FLAG_PASSIVE
      Else
         $nPassive = 0
      EndIf
      $aDllRet = DllCall($hWininet, "ptr", "InternetConnect", _
                         "ptr", $hInternet, _
                         "str", $sServer, _
                         "long", $INTERNET_DEFAULT_FTP_PORT, _
                         "str", $sUserName, _
                         "str", $sPassword, _
                         "long", $INTERNET_SERVICE_FTP, _
                         "long", $nPassive, _
                         "int", 0)
      If Not @error And $aDllRet[0] <> 0 Then
         $hConnect = $aDllRet[0]
         $aDllRet = DllCall($hWininet, "int", "FtpPutFile", _
                            "ptr", $hConnect, _
                            "str", $sLocalFile, _
                            "str", $sRemoteFile, _
                            "long", $nType, _
                            "int", 0)
         If Not @error Or $aDllRet[0] <> 0 Then
            $nRet = -1
         Else
            $aDllRet = DllCall("kernel32.dll", "long", "GetLastError")
            If Not @error Then $nRet = $aDllRet[0]
         EndIf
        ; Send QUIT command to ftp server
         $aDllRet = DllCall($hWininet, "int", "FtpCommand", _
                            "ptr", $hConnect, _
                            "int", 0, _
                            "long", $FTP_TRANSFER_TYPE_ASCII, _
                            "str", "QUIT", _
                            "int", 0, _
                            "int", 0)
         DllCall($hWininet, "int", "InternetCloseHandle", "ptr", $hConnect)
      EndIf
      DllCall($hWininet, "int", "InternetCloseHandle", "ptr", $hInternet)
   EndIf
   DllClose($hWininet)
   Return $nRet
EndFunc

Most other FTP commands will work using this method as well.

Have a look for WinInet functions on MSDN here

Share this post


Link to post
Share on other sites
Doxie

So many posts to read, and so little time...

No idea if anyone said it above, have you "activated" binary?

And i would recommend to use a command file with ftp.exe

Just like i did in my other post "New Project" (Just search my topics)


Were ever i lay my script is my home...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×