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
Connected to
220 Microsoft FTP Service
User ( ftpuser
331 Password required for ftpuser.
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.
Who is Participating?
r3helpdeskAuthor Commented:
Hello guys!

At the end WinSCP portable edition did the job. I will paste an example of my script maybe I'm not the only one who need this solution.

I created a .bat file which looks like this:

x:\path_to\ /script=script.txt

Open in new window

and here is the content of the script file:

option batch on
option confirm off
lcd x:\path_to\the_zip_file

Open in new window

Thank you all!
John KratzerCommented:
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.
r3helpdeskAuthor Commented:
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? 

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

John KratzerCommented:
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.
r3helpdeskAuthor Commented:
I did but the filter was a bit different. I kept the destination address (ftp server) as a constant (ip.dst == and as requests i cant see too many interesting things... as I said before, the "chat" is made in RAW:

PASS User@
PASS xxxxxxxxx
STOR test_file.rar
opts utf8 on

and then lots of ack and syn

what do you think?

John KratzerCommented:
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
lcd c:\
put  test_file.rar
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.  
r3helpdeskAuthor Commented:
@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.
r3helpdeskAuthor Commented:
In the end I found the solution.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.