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

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

#1 Post by sam14189 » 23 Jan 2015 11:16

Hi All,
I am trying to ftp a file using standard ftp command as - ftp -s:test.ftp. The "test.ftp" consist of below commands:
open 11.11.11.11
user
password
put file1
quit

The file is ftp'd successfully but the logs does not show me any return code as 0 or success message. I want some return code to be displayed so that if ftp is not successful due to any reason like - Connection failed, login incorrect or Traget not available then i can display message as "FTP was not successful". Can someone please help?

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

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

#2 Post by Squashman » 23 Jan 2015 11:42

You can redirect all the output from the FTP session to a file and then parse the log file for success or failures.

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

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

#3 Post by sam14189 » 25 Jan 2015 10:32

Squashman wrote:You can redirect all the output from the FTP session to a file and then parse the log file for success or failures.
yes I did that but I need some kind of return codes to check if ftp was successful.The current logs does not give any successful message when file gets ftp'd so it becomes very difficult to check status.

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

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

#4 Post by Squashman » 25 Jan 2015 10:47

I disagree. I use windows built-in ftp client about 300 times a day for my automation and it always returns a successul transfer in the output log when it transfers successcully.

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

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

#5 Post by sam14189 » 25 Jan 2015 13:08

Squashman wrote:I disagree. I use windows built-in ftp client about 300 times a day for my automation and it always returns a successul transfer in the output log when it transfers successcully.

Can u please let me know which command you are using to ftp the file? Is it ftp -d -s:temp.text? temp.text consist of all credentials.

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

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

#6 Post by Squashman » 25 Jan 2015 13:34

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"

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

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

#7 Post by sam14189 » 29 Jan 2015 03:59

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. i guess its not recognizing ftp -n -i option. Instead i used ftp -d but still it didnt give me "Transfer completed" message. Any pointers?

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

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

#8 Post by Squashman » 29 Jan 2015 08:21

sam14189 wrote:I tried using this command but it says invalid parameter. i guess its not recognizing ftp -n -i option. Instead i used ftp -d but still it didnt give me "Transfer completed" message. Any pointers?

If it is not recognizing the options then I would suspect there is another ftp client installed on your computer and it is not using Microsoft's built-in FTP client.
http://ss64.com/nt/ftp.html

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

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

#9 Post by sam14189 » 29 Jan 2015 08:47

Squashman wrote:
sam14189 wrote:I tried using this command but it says invalid parameter. i guess its not recognizing ftp -n -i option. Instead i used ftp -d but still it didnt give me "Transfer completed" message. Any pointers?

If it is not recognizing the options then I would suspect there is another ftp client installed on your computer and it is not using Microsoft's built-in FTP client.
http://ss64.com/nt/ftp.html

If that is the case then how can i check which ftp client is installed on my computer?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#10 Post by foxidrive » 29 Jan 2015 09:05

Open a cmd window and type ftp /? to see what it prints.

Which OS are you using?
This is what I see in Windows 8.1


Code: Select all

d:\>ftp /?

Transfers files to and from a computer running an FTP server service
(sometimes called a daemon). Ftp can be used interactively.

FTP [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-A] [-x:sendbuffer] [-r:recvbuffer] [-b:asyncbuffers] [-w:windowsize] [host]

  -v              Suppresses display of remote server responses.
  -n              Suppresses auto-login upon initial connection.
  -i              Turns off interactive prompting during multiple file
                  transfers.
  -d              Enables debugging.
  -g              Disables filename globbing (see GLOB command).
  -s:filename     Specifies a text file containing FTP commands; the
                  commands will automatically run after FTP starts.
  -a              Use any local interface when binding data connection.
  -A              login as anonymous.
  -x:send sockbuf Overrides the default SO_SNDBUF size of 8192.
  -r:recv sockbuf Overrides the default SO_RCVBUF size of 8192.
  -b:async count  Overrides the default async count of 3
  -w:windowsize   Overrides the default transfer buffer size of 65535.
  host            Specifies the host name or IP address of the remote
                  host to connect to.

Notes:
  - mget and mput commands take y/n/q for yes/no/quit.
  - Use Control-C to abort commands.

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

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

#11 Post by Squashman » 29 Jan 2015 09:16

Same output I get for Windows 7.

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

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

#12 Post by sam14189 » 29 Jan 2015 09:36

Squashman wrote:Same output I get for Windows 7.

Yes i am also using Windows 7 32 bit operating system and this is what i see:
C:\> ftp /?
Transfers files to and from a computer running an FTP server service
(sometimes called a daemon). Ftp can be used interactively.

FTP [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-A] [-x:sendbuffer] [-r:recvbuf
fer] [-b:asyncbuffers] [-w:windowsize] [host]

-v Suppresses display of remote server responses.
-n Suppresses auto-login upon initial connection.
-i Turns off interactive prompting during multiple file
transfers.
-d Enables debugging.
-g Disables filename globbing (see GLOB command).
-s:filename Specifies a text file containing FTP commands; the
commands will automatically run after FTP starts.
-a Use any local interface when binding data connection.
-A login as anonymous.
-x:send sockbuf Overrides the default SO_SNDBUF size of 8192.
-r:recv sockbuf Overrides the default SO_RCVBUF size of 8192.
-b:async count Overrides the default async count of 3
-w:windowsize Overrides the default transfer buffer size of 65535.
host Specifies the host name or IP address of the remote
host to connect to.

Notes:
- mget and mput commands take y/n/q for yes/no/quit.
- Use Control-C to abort commands.

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#13 Post by foxidrive » 29 Jan 2015 10:21

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.

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

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

#14 Post by Squashman » 29 Jan 2015 10:34

Why are you hell bent on using -D?

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

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

#15 Post by sam14189 » 30 Jan 2015 02:20

Squashman wrote:Why are you hell bent on using -D?

Because i want logs of ftp to check whether file was ftp'd or not. Apart from -d none of the other options are working in my case.

Post Reply