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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

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

#31 Post by Squashman » 30 Jan 2015 11:06

Try this in your script file. I have seen several FTP servers that don't like it when you don't specify the USER command. As you can see in my examples I always use it. I am not sure if that is why you are seeing INVALID COMMAND errors.
open 10.1.1.1
USER global123
globnew
bin
put myfile.txt myfilenew.txt
quit

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

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

#32 Post by sam14189 » 30 Jan 2015 11:17

Squashman wrote:Try this in your script file. I have seen several FTP servers that don't like it when you don't specify the USER command. As you can see in my examples I always use it. I am not sure if that is why you are seeing INVALID COMMAND errors.
open 10.1.1.1
USER global123
globnew
bin
put myfile.txt myfilenew.txt
quit

OK.. i will try this also and let you know the results.

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

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

#33 Post by foxidrive » 30 Jan 2015 17:37

I used your exact filenames and folders and batch file - just changing the script as below
as Squashman suggested by adding user and also separating the put commands:

Code: Select all

open astronomy.com
user captainkirk
enterprise
bin
put myfile.txt
put myfilenew.txt
quit


and this is the log file:

Code: Select all

ftp> open astronomy.com
Connected to astronomy.com.
220---------- Welcome to Pure-FTPd [privsep] ----------
220-You are user number 24 of 500 allowed.
220-Local time is now 18:32. Server port: 21.
220-This is a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
ftp> user captainkirk
331 User captainkirk OK. Password required

230-OK. Current restricted directory is /
230-225 files used (2%) - authorized: 10000 files
230 155390 Kbytes used (10%) - authorized: 1536000 Kb
ftp> bin
200 TYPE is now 8-bit binary
ftp> put myfile.txt
200 PORT command successful
150 Connecting to port 52718
226-226 files used (2%) - authorized: 10000 files
226-155390 Kbytes used (10%) - authorized: 1536000 Kb
226-File successfully transferred
226 0.560 seconds (measured here), 132.17 bytes per second
ftp: 74 bytes sent in 0.28Seconds 0.26Kbytes/sec.
ftp> put myfilenew.txt
200 PORT command successful
150 Connecting to port 52719
226-227 files used (2%) - authorized: 10000 files
226-155390 Kbytes used (10%) - authorized: 1536000 Kb
226-File successfully transferred
226 0.556 seconds (measured here), 136.80 bytes per second
ftp: 76 bytes sent in 0.28Seconds 0.28Kbytes/sec.
ftp> quit
221-Goodbye. You uploaded 1 and downloaded 0 kbytes.
221 Logout.

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

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

#34 Post by Squashman » 30 Jan 2015 18:04

Foxidrive,
He is just uploading one file. The second file name in the put statement is file name you want it to be on the ftp site. Basically renaming the file on the upload.

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

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

#35 Post by foxidrive » 30 Jan 2015 18:59

Squashman wrote:Foxidrive,
He is just uploading one file. The second file name in the put statement is file name you want it to be on the ftp site. Basically renaming the file on the upload.


Thank you - I wasn't aware of that.

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

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

#36 Post by sam14189 » 02 Feb 2015 02:26

Hi Squashman and foxidrive - I tried using the way you mentioned, it worked but using -n and -i options i am not able to see logs at all. I can only see below in log file:

open 10.1.1.1
user global123

bin
myfile.txt myfilenew.txt
quit

So even if file was ftp'd but no logs are generated at all.

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

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

#37 Post by Squashman » 02 Feb 2015 07:30

I have no idea what could be wrong with your system. I literally generate hundreds of FTP logs every day with the automation I do. I have never seen the log file not come out correctly

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

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

#38 Post by sam14189 » 02 Feb 2015 07:33

Squashman wrote:I have no idea what could be wrong with your system. I literally generate hundreds of FTP logs every day with the automation I do. I have never seen the log file not come out correctly

Thanks Squashman for being patient and suggesting so many solutions! I will have to look for some other approach to find whether files were ftp'd or not :(

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

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

#39 Post by foxidrive » 02 Feb 2015 15:47

sam14189 wrote:Thanks Squashman for being patient and suggesting so many solutions! I will have to look for some other approach to find whether files were ftp'd or not :(


What you should really do is show how you are doing this - because the problem is 99% guaranteed to be an error on your part in the way your script is running.

We can only help people fix their code when we can see the code and know how it is being launched - it makes sense, right?
Type over your password and username and servername - or use captainkirk - and give all the details.

The text you've shown above is basically the FTP script itself.

See here: viewtopic.php?f=3&t=6108

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

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

#40 Post by Squashman » 02 Feb 2015 15:56

Yes. I have seen some weird goofy output get redirected to FTP log files when the FTP command is being used with a script and being called from a 3rd party program. One of my automation applications has a tendency to output the script file to the log file yet executes without any problems. I figured out a work around for it, but the software vendor has no clue why it is happening.

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

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

#41 Post by sam14189 » 03 Feb 2015 07:31

OK. I will tell you the exact process.However i can not mention server name, user id and password due to copyright issues. I hope you understand that. This is what i am trying to do:

There is a tool called IBM WTX, basically a application which does some other processing apart from executing this batch script to ftp the file.This WTX is not running on windows rather this application is deployed on server. For this reason we have kept our batch script program also on server. When the file is ftp'd it is posted to another server via the firewall. So i am assuming the logs are not getting displayed properly due to firewall in between. Here are the contents of file:

Batch File:demo.bat

Code:
ftp -i -n -s:"<server path>\temp.txt" >"<server path>\logs.txt"
Contents of temp.txt

Code:
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:
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:
ftp -d -s:"<server path>\temp.txt" >"<server path>\logs.txt"

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

Code:
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.

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

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

#42 Post by Squashman » 03 Feb 2015 07:54

sam14189 wrote:Hi Squashman and foxidrive - I tried using the way you mentioned, it worked but using -n and -i options i am not able to see logs at all. I can only see below in log file:

open 10.1.1.1
user global123

bin
myfile.txt myfilenew.txt
quit

So even if file was ftp'd but no logs are generated at all.

So you are no longer getting the INVALID COMMAND error when your run it with the USER command in the script.

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

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

#43 Post by sam14189 » 03 Feb 2015 09:59

Squashman wrote:
sam14189 wrote:Hi Squashman and foxidrive - I tried using the way you mentioned, it worked but using -n and -i options i am not able to see logs at all. I can only see below in log file:

open 10.1.1.1
user global123

bin
myfile.txt myfilenew.txt
quit

So even if file was ftp'd but no logs are generated at all.

So you are no longer getting the INVALID COMMAND error when your run it with the USER command in the script.

Yes that is correct. When i run with "USER" command then invalid error is gone but logs are not generated.

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

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

#44 Post by Squashman » 03 Feb 2015 12:01

Manually login to the FTP server from the cmd prompt.
They type: STATUS

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

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

#45 Post by foxidrive » 03 Feb 2015 19:45

You didn't add user in here.


sam14189 wrote:Code:
open 10.1.1.1
global123
globnew
bin
put myfile.txt myfilenew.txt
quit


Squashman mentioned that long ago:

viewtopic.php?p=39668#p39668

Post Reply