Run ftp from a command prompt to put a file
I am experimenting with running ftp from a command prompt on a Windows Server 2008 R2 platform. I have code in a vbscript file that uses a vendor product to ftp a file. I should just be able to shell out and run the "native" ftp command to put the file to the destination ftp site and eliminate the need for the 3rd party software. Here is my code:
Code:
Dim oMySite
Set oMySite = CreateObject("CuteFTPPro.TEConnection")
oMySite.Protocol = "FTP"
oMySite.Host = "xx.xx.xx.xx"
oMySite.Login = "id"
oMySite.Password = "pw"
oMySite.Connect
oMySite.RemoteFolder = "/remotefolder/mmock"
oMySite.LocalFolder = sTempPath & "\"
oMySite.Upload "file_to_put.txt"
oMySite.Disconnect
oMySite.Close
I have just begun researching this and I wrote a script but I get invalid command even though it's the same commands in the script that I just entered one-by-one into an OS shell window. Does anyone have a script they know works that they could share, or know of a way to debug what my invalid command might be?
Thanks.
Re: Run ftp from a command prompt to put a file
I'm a little confused. Why not just use Windows' own FTP.EXE and pass it a "script" (file of commands just as you'd enter by hand) via the -s switch?
Re: Run ftp from a command prompt to put a file
That's what I'm doing:
Quote:
Originally Posted by
MMock
I wrote a script but I get invalid command ...
I was looking for an example script file that's known to work because I don't know what my invalid command is.
Re: Run ftp from a command prompt to put a file
Microsoft doesn't explain what the line "user" is for:
http://support.microsoft.com/kb/96269
FTP is capable of using scripts (lists of commands from external files). The following example demonstrates a script that opens a connection to IP address 11.11.11.11, logs on to the host as a guest with the password "guest," uploads the File1 file, and then quits:
open 11.11.11.11
user
guest
guest
put file1
quit
Re: Run ftp from a command prompt to put a file
Is it different if the operating system running on is Windows Server 2008 R2?
Re: Run ftp from a command prompt to put a file
It's not reading my credentials. If I run it like this:
ftp -s:script.txt 11.11.11.11
It says I am connected to the host, then it says:
User (11.11.11.11: (none))
Please specify the password
Re: Run ftp from a command prompt to put a file
I'd guess somebody goofed.
They were probably thinking they had to enter the USER command to log on, and then put in the user (guest) and pw (guest).
Just put the same responses and commands you would enter manually into the text "script" file. Don't forget a bye/quit at the end.
Re: Run ftp from a command prompt to put a file
Quote:
Originally Posted by
dilettante
Just put the same responses and commands you would enter manually into the text "script" file.
Yea. I don't know why this is so hard. The commands work fine from the command prompt, then I batch them into a script and they aren't working.
If my script contains
open 11.11.11.11
id
pw
cd this_folder
cd another_folder
put testfile.txt
quit
This is what comes back:
ftp> o
Invalid command
ftp>
ftp>
ftp>
ftp>
ftp>
ftp>
ftp>
ftp>
ftp>
There is an unprintable character on the first line beofre the o.
If my script contains
id
pw
cd this_folder
cd another_folder
put testfile.txt
quit
and I run it as ftp -s:script.txt 11.11.11.11, I get
Connected to 11.11.11.11
220 (vsFTPd 2.0.5)
User(11.11.11.11: (none)):
331 Please specify the password.
530 Login incorrect.
Login failed.
ftp>
ftp>
ftp>
ftp>
ftp>
ftp>
ftp>
Re: Run ftp from a command prompt to put a file
Is it possible to test the process using another OS (WinXP, Vista, etc.)?
Unless the Server 2008 R2 FTP.exe is subtly different in its command structure from older versions this should work.
Of course entering those by hand was working for you... hmm.
Aside from possible junk characters in the text "script" file I'm not sure what might be happening here. Have you tried using the -n switch along with -s: to suppress any attempt to autologon using your Windows credentials?
Re: Run ftp from a command prompt to put a file
I ran it on my PC, which is Windows XP, and I basically got the same thing. It doesn't seem to be reading the value of the id because it echos back "User" with the IP I'm successfully connected to, and (none) is in the string as if it doesn't know who I'm trying to say I am. I will try the -n switch. I was also thinking of testing with another ftp site, to see if it could possibly be something unique with the site I am using.
Re: Run ftp from a command prompt to put a file
The User prompt displays the default user to log on with. Generally this is "none" i.e. "do an anonymous logon."
The default user is accepted by entering a null input, i.e. just press the Enter key.