Windows ftp command "Ftp Connection closed by remote host"

Posted on 2011-05-03
Last Modified: 2012-05-11
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.
Question by:r3helpdesk
    LVL 6

    Expert Comment

    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.

    Author Comment

    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?

    LVL 6

    Expert Comment

    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.

    Author Comment

    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:

    CWD /
    PASS User@
    PASS xxxxxxxxx
    STOR test_file.rar
    TYPE A
    opts utf8 on

    and then lots of ack and syn

    what do you think?

    LVL 6

    Expert Comment

    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
    LVL 16

    Expert Comment

    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.
    LVL 16

    Expert Comment

    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.  

    Author Comment

    @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.

    Accepted Solution

    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!

    Author Closing Comment

    In the end I found the solution.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    This article was inspired by a question here at Experts Exchange ( The requirements stated in that question are (1) reduce the file size of a large number of…
    Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now