Link to home
Start Free TrialLog in
Avatar of r3helpdesk
r3helpdesk

asked on

Windows ftp command "Ftp Connection closed by remote host"

Hello there!

The ftp.exe command from Windows returns the following error "Connection closed by remote host" a while after the "send" comment has been executed.  Any idea why? I want also to mention that the copy action works perfectly with explorer.

Returning data looks like this:

ftp> open xxx.xxx.xxx.xxx
Connected to xxx.xxx.xxx.xxx.
220 Microsoft FTP Service
User (xxx.xxx.xxx.xxx:(none)): ftpuser
331 Password required for ftpuser.
Password:
230 User ftpuser logged in.
ftp> debug
Debugging on .
ftp> literal pasv
---> pasv
227 Entering Passive Mode (xxx,xxx,xxx,xxx,223,18).
ftp> lcd c:\
Local directory now C:\.
ftp> send test.rar test.rar
---> PORT xxx,xxx,xxx,xxx,220,249
Connection closed by remote host.
Avatar of John Kratzer
John Kratzer
Flag of United States of America image

When conducting the transfer in batch, is the file transferring?

You may be able to contact the FTP providor to get the error from there end to see what is going on.

Try using the put command instead of the send command for the file transfer.

To see exactly what is happening when you are sending the file through explorer, run a sniffer application (wireshark) to see what commands explorer is sending.
Avatar of r3helpdesk
r3helpdesk

ASKER

What do you mean with "is the file transferring?

I did but no response until now...

Tried even the put command but is not working.

Yes I can do that but... you can see only the RAW commands... how can I translate a RAW command into a command for ftp.exe? 

Look for request lines in the capture.

It would also help if you create a filter for FTP using "tcp port ftp" so you only see the FTP session.
I did but the filter was a bit different. I kept the destination address (ftp server) as a constant (ip.dst == xxx.xxx.xxx.xxx) and as requests i cant see too many interesting things... as I said before, the "chat" is made in RAW:

CWD /
LIST
PASS User@
PASS xxxxxxxxx
PASV
PWD
STOR test_file.rar
TYPE A
noop
opts utf8 on
syst

and then lots of ack and syn

what do you think?

Looks about correct.

Can you get the logfile from the providor?

I also note that some servers do not like literal pasv.
I tested on one of my FTP servers and got the same response when you use literal pasv.

Set your script to run the commands reflected in the same order you saw from explorer.

Script response file should look something like this...
I added hash so you can watch it transfer.

open xx.xx.xx.xx
user Username
PASS password
PASV
hash
binary
lcd c:\
put  test_file.rar
bye
Are you sure the windows FTP client even supports passive mode?  Clearly the remote server does because it sent a positive response but I'm not so sure about ftp.exe.  I suspect the remote server disconnected after a while because ftp.exe did not initiate the data channel on the port specified in the PASV response.  You might need to use a different FTP client.
Robo-FTP is a scriptable FTP client that supports passive mode.  It was basically designed to automate repetitive file transfers so it should be able to handle your batch processing.  
@jkratzer first I want to thank you for your replay but, is not working even using this order of commands. I think the PASV mode is not working correctly...

@AlexPace I agree with you, it must be a problem with ftp.exe initiating the transfer... I will give a shot with winscp, if I remember correctly, winscp is capable of scripting too and is also free :) Thank you

I will update the post after testing this idea.
ASKER CERTIFIED SOLUTION
Avatar of r3helpdesk
r3helpdesk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In the end I found the solution.