FTP Passive Commands VB

Posted on 2004-11-22
Last Modified: 2013-11-13
I am using a VB application that I have made to upload files using FTP. But I cannot get passive commands to work on it. Could you tell me how I could use the passive mode for FTP upload and what the commands would be?
Question by:hanselds
    LVL 1

    Expert Comment

    Are you using an FTP component or are you implementing the connection yourself using winsock?
    The PASV command has to be sent to the server. Then, the server gives you an IP and a port number (the port number needs translation), and the client needs to open another TCP connection to this IP and port to establish the data connection.

    Author Comment

    It is my own application made using the winsock control. I want to know how to initialise the passive mode and how to send the command
    LVL 8

    Expert Comment

    I once this component which is open source

    please be aware that you can either
    - use the component,
    - use source from it and release your library gpl,
    - buy a non-gpl source license

    I'd suggest you just use their component as it is, it works fine
    LVL 85

    Accepted Solution

    You simply send the PASV command followed by vbCrLF:

        ControlConnection.SendData "PASV" & vbCrLf

    The server should come back with a 227 repsonse similiar to the below:

        227 Entering Passive Mode (IP1, IP2, IP3, IP4, P1, P2)

    The "Entering Passive Mode" message may vary from FTP server to server, or may not even be present at all.  The parenthesis may not be there either, but most servers put them there.  The FTP protocol doesn't actually specify how the 227 response message should be formatted, so you have to do some intelligent parsing.  You can either look for the left and right parenthesis, or start looking for the first digit after the three digit response.  There also may or may not be spaces after the commas seperating the values.  Once you are confident you have found all the values, you put them together like this:

        IP = IP1.IP2.IP3.IP4
        Port = (P1 * 256) + P2

    Then, you initiate a connection on a new winsock control to the IP and Port you just received.

    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Once you have established your new data connection to the specifed IP and Port, send a RETR command on the control connection and the file will start streaming across your new data connection.

    LVL 8

    Expert Comment

    Idle_Mind deserves'em imo

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    If you haven’t already, I encourage you to read the first article ( in my series to gain a basic foundation of R and R Studio.  You will also find the …
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    This video teaches viewers about errors in exception handling.
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

    758 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

    10 Experts available now in Live!

    Get 1:1 Help Now