FTP a file:Get return code if ftp is unsucessful.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
sam14189
Posts: 31
Joined: 22 Jan 2015 02:57

Re: FTP a file:Get return code if ftp is unsucessful.

#16 Post by sam14189 » 30 Jan 2015 06:22

foxidrive wrote:
sam14189 wrote:
Squashman wrote:All my FTP commands are launched from batch files like this.

Code: Select all

ftp -n -i -s:"E:\PathtoBatchFiles\ClientNameFTPscript.scr" >"E:\PathtoLogFiles\ClientNameFTPscript.txt"

I tried using this command but it says invalid parameter.


sam14189 wrote:I am not sure why -n is not working :( :(


Paste in the exact command you used and the reason may become clear.

ftp -i -n -s:"C:\temp.txt" >logs.txt
The contents of temp.txt are:

open 10.1.1.1
username
password
bin
put sourcefile destination path
quit

It is giving me below error:
Invalid command.
Invalid command.

Squashman
Expert
Posts: 4473
Joined: 23 Dec 2011 13:59

Re: FTP a file:Get return code if ftp is unsucessful.

#17 Post by Squashman » 30 Jan 2015 07:18

Are you running that from the Command Prompt or a Batch file?
If you are running it from a batch file what is the name of the batch file.

sam14189
Posts: 31
Joined: 22 Jan 2015 02:57

Re: FTP a file:Get return code if ftp is unsucessful.

#18 Post by sam14189 » 30 Jan 2015 07:54

Squashman wrote:Are you running that from the Command Prompt or a Batch file?
If you are running it from a batch file what is the name of the batch file.

I am running it from a batch file. The name of batch file is ftp.bat

Squashman
Expert
Posts: 4473
Joined: 23 Dec 2011 13:59

Re: FTP a file:Get return code if ftp is unsucessful.

#19 Post by Squashman » 30 Jan 2015 07:59

sam14189 wrote:ftp.bat

And Bingo was his name oh!!!!!!

sam14189
Posts: 31
Joined: 22 Jan 2015 02:57

Re: FTP a file:Get return code if ftp is unsucessful.

#20 Post by sam14189 » 30 Jan 2015 08:07

Squashman wrote:
sam14189 wrote:ftp.bat

And Bingo was his name oh!!!!!!

Is it a problem? I dont think so because in that case it would not have worked with ftp -d option as well.

Squashman
Expert
Posts: 4473
Joined: 23 Dec 2011 13:59

Re: FTP a file:Get return code if ftp is unsucessful.

#21 Post by Squashman » 30 Jan 2015 08:15

sam14189 wrote:Is it a problem? I dont think so because in that case it would not have worked with ftp -d option as well.


Code: Select all

ftp -i -n -s:"C:\temp.txt" >logs.txt


Your batch file doesn't know the difference between FTP.EXE and FTP.BAT because you are not specifying a file extension.

If a batch file needs to execute an external command the first place it looks for that command is the Current Working Directory. Then it looks for the command in the PATH variable and finally will look for it in the registry.

Basically, your batch file is trying to execute itself instead of FTP.exe

sam14189
Posts: 31
Joined: 22 Jan 2015 02:57

Re: FTP a file:Get return code if ftp is unsucessful.

#22 Post by sam14189 » 30 Jan 2015 09:10

Squashman wrote:
sam14189 wrote:Is it a problem? I dont think so because in that case it would not have worked with ftp -d option as well.


Code: Select all

ftp -i -n -s:"C:\temp.txt" >logs.txt


Your batch file doesn't know the difference between FTP.EXE and FTP.BAT because you are not specifying a file extension.

If a batch file needs to execute an external command the first place it looks for that command is the Current Working Directory. Then it looks for the command in the PATH variable and finally will look for it in the registry.

Basically, your batch file is trying to execute itself instead of FTP.exe

Sorry i am naive to this Batch script :( . So what should i do? Rename the ftp.bat to someother name like demo.bat and then insert the below command?
ftp -i -n -s:"C:\temp.txt" >logs.txt
So when demo.bat is executed it should work fine? Is that you are stating?

Squashman
Expert
Posts: 4473
Joined: 23 Dec 2011 13:59

Re: FTP a file:Get return code if ftp is unsucessful.

#23 Post by Squashman » 30 Jan 2015 09:14

YES :!:

sam14189
Posts: 31
Joined: 22 Jan 2015 02:57

Re: FTP a file:Get return code if ftp is unsucessful.

#24 Post by sam14189 » 30 Jan 2015 09:47

Squashman wrote:YES :!:

It didnt work! i renamed my file to demo.bat and using below command:
ftp -i -n -s:"C:\temp.txt" >"C:\logs.txt"

When demo.bat is executed then i could see below in my logs.txt file:
Invalid command.
Invalid command.
open 10.1.1.1
user
password
bin
Please login with USER and PASS.
put sourcefile destinationfile
Please login with USER and PASS.
Please login with USER and PASS.
quit

When i used: ftp -d -s:"C:\temp.txt" >"C:\logs.txt" then logs.txt consist of:

User (10.1.1.1:(none)): open 10.1.1.1
--->
USER user
--->
PASS password
---> bin
TYPE I
---> put sourcefile destinationfile
PORT 1,2,3,4,5,6
---> STOR destinationfile
---> quit
QUIT

And file was ftp'd on server. So this is the reason i mentioned that even if file is ftp'd i could not see any succesful message in the logs.

Squashman
Expert
Posts: 4473
Joined: 23 Dec 2011 13:59

Re: FTP a file:Get return code if ftp is unsucessful.

#25 Post by Squashman » 30 Jan 2015 10:12

Contents of my working directory

Code: Select all

C:\FTP>dir /a-d /b
ftpbatch.bat
ftpscript.txt
uploadme.txt

Contents of the batch file

Code: Select all

C:\FTP>type ftpbatch.bat
ftp -n -i -s:"ftpscript.txt">"FTP.log"

Contents of the Script file

Code: Select all

C:\FTP>type ftpscript.txt
open 192.168.1.10
user Squashman
mypassword
ascii
put uploadme.txt
quit

Executing the batch file

Code: Select all

C:\FTP>ftpbatch.bat

C:\FTP>ftp -n -i -s:"ftpscript.txt" 1>"FTP.log"

Contents of the Log file

Code: Select all

C:\FTP>type ftp.log
ftp> Connected to 192.168.1.10.
open 192.168.1.10
220 Microsoft FTP Service
ftp> user Squashman
331 Password required for Squashman.

230 User Squashman logged in.
ftp> ascii
200 Type set to A.
ftp> put uploadme.txt
200 PORT command successful.
150 Opening ASCII mode data connection for uploadme.txt.
226 Transfer complete.
ftp: 7 bytes sent in Seconds Kbytes/sec.
ftp> 0.160.05quit
221

C:\FTP>

sam14189
Posts: 31
Joined: 22 Jan 2015 02:57

Re: FTP a file:Get return code if ftp is unsucessful.

#26 Post by sam14189 » 30 Jan 2015 10:20

Thanks Squashman for being patient! I dont know why its not working for me :cry: I think in my case file is posted to server via firewall. So that might be the reason -n -i options are not recognizable. Not sure though...I am still thinking how i can figure out if file is ftp'd or not from the logs..

Squashman
Expert
Posts: 4473
Joined: 23 Dec 2011 13:59

Re: FTP a file:Get return code if ftp is unsucessful.

#27 Post by Squashman » 30 Jan 2015 10:25

Try it without the -I option.
ftp -n -s:"C:\ftpscript.txt"

Then try it without the -I and -N option.
ftp -s:"C:\ftpscript.txt"

sam14189
Posts: 31
Joined: 22 Jan 2015 02:57

Re: FTP a file:Get return code if ftp is unsucessful.

#28 Post by sam14189 » 30 Jan 2015 10:28

Squashman wrote:Try it without the -I option.
ftp -n -s:"C:\ftpscript.txt"

Then try it without the -I and -N option.
ftp -s:"C:\ftpscript.txt"


I did that already.1) is not working..2) It works but logs details are not sufficient.

Squashman
Expert
Posts: 4473
Joined: 23 Dec 2011 13:59

Re: FTP a file:Get return code if ftp is unsucessful.

#29 Post by Squashman » 30 Jan 2015 10:37

I do data automation for a living. I manage over 600 automation tasks. Many of them being FTP.
If the batch file is using the Windows FTP client there should not be any problems.
Since you said it was successful but the log was not correct, please repost the batch file, ftp script and log again.

Just for future reference, I would not write your log files to the root of the C: drive.
On Windows Vista and above you can not write to the root of the C: drive without running the program with elevated privileges.

Code: Select all

C:\>echo blah >log.txt
Access is denied.

sam14189
Posts: 31
Joined: 22 Jan 2015 02:57

Re: FTP a file:Get return code if ftp is unsucessful.

#30 Post by sam14189 » 30 Jan 2015 10:49

Batch File:demo.bat

Code: Select all

ftp -i -n -s:"D:\New\temp.txt" >"D:\New\logs.txt"

Contents of temp.txt

Code: Select all

open 10.1.1.1
global123
globnew
bin
put myfile.txt myfilenew.txt
quit


When demo.bat is executed then logs.txt consist of:

Code: Select all

Invalid command.
Invalid command.
open 10.1.1.1
global123
globnew
bin
Please login with USER and PASS.
put myfile.txt myfilenew.txt
Please login with USER and PASS.
Please login with USER and PASS.
quit


Batch File:demo.bat

Code: Select all

ftp -d -s:"D:\New\temp.txt" >"D:\New\logs.txt"


Keeping the contents of temp.txt same, when demo.bat is executed then logs.txt consist of:

Code: Select all

User (10.1.1.1:(none)): open 10.1.1.1
--->
USER global123
--->
PASS globnew
---> bin
TYPE I
---> put myfile.txt myfilenew.txt
PORT 1,2,3,4,5,6
---> STOR myfilenew.txt
---> quit
QUIT


And i checked on server, myfilenew.txt was transmitted.

Post Reply