Windows ftp client using different port

Someone, please help.  A client of ours has an ftp server set up to listen on port 2525 and we are trying to set up an automated posting to this server.  We have no problem using FileZilla doing the post manually, but when we try to post using the command line ftp with a batch file, it fails...the batch file is as follows:

  open ftp.hostname.com 2525
  ftp_user
  ftp_password
  cd import
  binary
  put \send\filename.txt.pgp
  close
  quit

When run from a command line, the response is:

  ftp> open ftp.hostname.com 2525
  Connected to ftp.hostname.com.
  220 ProFTPD 1.3.3c Server (hostname) [123.123.123.123]
  User (ftp.hostname.com:(none)): ftp_user
  331 Password required for ftp_user
  Password:
  230 User ftp_user logged in
  ftp> cd import
  250 CWD command successful
  ftp> binary
  200 Type set to I
  ftp> put \send\filename.txt.pgp
  500 Illegal PORT command
  425 Unable to build data connection: Connection refused
  ftp> Close
  221 Goodbye.
  ftp> Quit

and we end up with a zero-length file on the server...the file is created but the contents are not transferred.

I've tried using other command line apps and get the same result...psftp, winscp, moveit all failed.

Anyone have any ideas??
DalexanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
Have you tried passive mode?

After you connect type:
QUOTE PASV

(haven't needed it myself in a while)
0
DalexanAuthor Commented:
pasv is not an option in windows command line ftp...
0
Robert SchuttSoftware EngineerCommented:
No, but when you use QUOTE PASV it is executed on the server. It must be a firewall problem when data connection is opened on another port. Possibly when you use it interactively it automatically adjusts or it is already configured.
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

DalexanAuthor Commented:
looks like that didn't work...I got '500 Illegal port command' and no ftp> prompt...it's hung.
0
Robert SchuttSoftware EngineerCommented:
Have you got a way to check if a firewall is blocking the incoming connection?

Also, use the -d switch to debug ftp, on this site it's explained what the PORT debugging means: http://slacksite.com/other/ftp.html
0
DalexanAuthor Commented:
No luck...the -d option didn't give any additional info...everything works until I get to the PUT command.  I'd have to check with the client to see if they have a firewall on...but FileZilla works fine for transferring files manually...wouldn't a firewall stop it from working also?
0
Gerwin Jansen, EE MVETopic Advisor Commented:
Hi, I use WinSCP scripting for things like this, here's the documentation: http://winscp.net/eng/docs/scripting
0
Robert SchuttSoftware EngineerCommented:
Well that's the thing, it could be that the firewall is on the client (your) side because a new connection is opened up to send the data to you. This is not on port 21 or 2525 but a new port.

FileZilla might be configured (or automatically try) to switch modes when necessary. I actually use Total Commander for most of my FTP needs and in there it's just a checkbox in the configuration of a connection.
0
Robert SchuttSoftware EngineerCommented:
I see I had it backwards, you were right earlier, it would be at the server side, because you're not trying to GET but PUT a file... Some firewalls allow those ports automatically for the FTP protocol, maybe theirs is a bit too strict?
0
Robert SchuttSoftware EngineerCommented:
When I use "ftp -d" I get this extra info, but the port number is not fixed:

ftp> put tst.txt
---> PORT 192,168,1,33,223,126
200 PORT command successful
---> STOR tst.txt
150 Connecting to port 18419
226-File successfully transferred
0
David Johnson, CD, MVPOwnerCommented:
which ftp server is your friend using?

server: Microsoft IIS 7.5
Client c:\windows\ftp.exe

ftpme.txt
o localhost 2525
ftp_user
ftp_pass
bin
hash 
put c:\write-log.ps1
quit

Open in new window


console output
C:\>ftp -s:ftpme.txt
ftp> o localhost 2525
Connected to DavidJohnson-W7.
220 Microsoft FTP Service
User (DavidJohnson-W7:(none)):
331 Password required for ftp_user

230-User logged in.
 Win32 error:   The operation completed successfully.
 Error details: File system returned an error.
230 End
ftp> bin
200 Type set to I.
ftp> hash
Hash mark printing On  ftp: (2048 bytes/hash mark) .
ftp> put c:\write-log.ps1
200 PORT command successful.
125 Data connection already open; Transfer starting.

226 Transfer complete.
ftp: 1006 bytes sent in 0.00Seconds 1006000.00Kbytes/sec.
ftp> quit
221 Goodbye.

C:\>

Open in new window

0
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
Are you certain that the FTP Server is normal FTP?  It may be FTP/SSL (FTPS) or FTP/SSH (SFTP), in either case the connection would not work properly through the normal FTP command.

From what I recall if the server is using either of these encryption methods it would most likely be FTP/SSL since that can allow a regular connection for commands browsing but encrypt just the data portion.

Otherwise the FTP server may be using a special set of ports for data as well as commands, and FTP will try 21 by default.  However if this were the case then your commands should be failing regardless.. So I don;t think that is the case.  (FYI: I believe the Windows CMD Line FTP DOES NOT support Passive, only Active connections, in an Active connection the FTP Client chooses the port it will look for responses back on and talks to the FTP Server's default data port.  In Passive the FTP Server specifies it's data port and tells the client which port it should connect on.)

 It looks like this is the case though, as the FTP account is accepted and we see the port command in debug and then you can try to put the file.

For the "By Hand" Command Line, try NOT using Binary, it's often not necessary, and I have seen using the Binary command lead to Zero Length files.

As for the "Batch File", you cannot put FTP Commands directly in a batch file you must write an FTP Script as a separate file and then put it into the command line argument:

Save the following File as "C:\FTPScript\FTPSend.ftp"
Put the file you want to send in "C:\FTPScriptput\filename.txt.pgp"
Then Run the Command specified after the script file.
Note 1: I have removed the "Binary" command, you can add it back in if necessary.
Note 2: It is possible to make this process work for changing files and directories by creating a batch script which writes the FTP Script and then executes it, I have successfully used this to backup changing file names in different environments.

:: FTP Script name: FTPSend.ftp

"ftp_user"
ftp_password
cd import
put "C:\FTPScript\filename.txt.pgp"
quit

Open in new window

Once you have the above saved in "C:\FTPScript\FTPSend.ftp", just run this command:
FTP -s:"C:\FTPScript\FTPSend.ftp" ftp.hostname.com:2525 

Open in new window

0
DalexanAuthor Commented:
The server is 220 ProFTPD 1.3.3c Server
0
Paul TomasiCommented:
Dalexan

Have you tried:

   open ftp.hostname.com:2525

instead of:

   open ftp.hostname.com 2525

Notice the colon separating the domain name and the port number.
0
Robert SchuttSoftware EngineerCommented:
Reading this I would say forget about passive mode but make sure port 20 is available, although it might be port 2524 in your case because I've read somewhere that an FTP server might choose the current port number minus 1.
0
David Johnson, CD, MVPOwnerCommented:
@Dalexan: awaiting any response from you.
0
JT92677Commented:
I tried this on one of my non-standard port servers, and it doesn't work from the CMD: ftp client.

It looked reasonable up to the CD where the system gave me the Error 500.

Suggestion:
 
Try adding a line in the text response file-- the "quote pasv" line - switches to passive mode.
Prove to yourself it won't work?  How's that for an expert suggestion ?? <<grin>>
Sorry

 open ftp.hostname.com 2525
  ftp_user
  ftp_password
 quote pasv
  cd import
  binary
  put \send\filename.txt.pgp
  close
  quit

ERROR 500

hmmmm
0
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
As I mentioned in my post above, Windows command line does not support Passive.

  I also use the URL:Port nomenclature in my post above; as Paul mentioned afterwards this should be the preferred method.

  However, if the FTP is active then you should still be able to issue commands (which you do), at least so long as they return data (such as a directory listing).

  The fact you are able to issue commands and begin putting the file is promising, as I have seen instances where for some reason putting the file with binary does leave a 0-byte file.

So it might be that you need to put the file ASCII instead of Binary; however, if that does not work, and directory listing also does not work, then it is not possible without a 3rd party FTP Client.

-Q
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JT92677Commented:
Qcubed - The URL:Port works in the browser, but on the CMD prompt, the syntax for ftp open is a space between the URL and the port number:  URL  PORT  not URL:PORT   Maybe this is because the router is taking the non-standard incoming port, and routing packets to the ftp server, AND changing the port inside the LAN to 21. Maybe that's it? Not sure.

The passive command is a server issue isn't it?  When the user sends Quote pasv it requests that the ftp server go into passive mode. It shouldn't change the client (ftp in the cmd mode). Right?

I've issued the command in Windows version 7 (and earlier versions) and it gets a positive response from the ftp server that it is entering passive mode.

Unfortunately, even in passive mode, the error 500 still comes up on almost all file related requests made to the ftp server.

It will be interesting if ANY solution for the cmd line version of ftp.exe will work with non-standard ports (not 21).

Jeff
0
David Johnson, CD, MVPOwnerCommented:
proFtp latest version is 1.3.4a..

It is not a problem with the ftp.exe it works as shown below.

C:\Users\David Johnson>ftp
ftp> o localhost 2525
Connected to DavidJohnson-W7.
220 Microsoft FTP Service
User (DavidJohnson-W7:(none)): David Johnson
331 Password required for David Johnson.
Password:
230-Directory has 171,212,177,408 bytes of disk space available.
230 User logged in.
ftp> put c:\*.txt
200 PORT command successful.
125 Data connection already open; Transfer starting.
226 Transfer complete.
ftp: 12 bytes sent in 0.11Seconds 0.11Kbytes/sec.
ftp> ls
200 PORT command successful.
125 Data connection already open; Transfer starting.
adminfiles
aspnet_client
computers.txt
LocalUser
notepad.ps1
write-log.ps1
226-Directory has 171,214,270,464 bytes of disk space available.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.