passive mode how do i set in code

0 votes
asked Oct 21, 2016 by philj (140 points)
edited Oct 21, 2016 by philj

I am using sftp to connect to a sftp directory but when passive mode is not selected in filezilla i cannot connect and the same goes for when i attempt my normal code which is as below how would one enable the code for passive mode sftp.

The error that i get is the following says username and password incorrect but i no its not as I can connect in filezilla with passive mode being active.

public void sendFileToSftp(string filename, string serverFile, string IVARef, string firstname,string lastname,string hostname, string port, string username, string password)

        // create client, connect and log in
        Sftp client = new Sftp();

        client.Login(username, password);
        client.TransferProgressChanged += new EventHandler<SftpTransferProgressChangedEventArgs>(sftp_TransferProgressChanged);
        client.CreateDirectory(IVARef + " " + firstname + "  " + lastname);
        // upload the '' file to the current directory at the server
        client.PutFile(filename, serverFile);

    catch (Exception ex)

        string inner = string.Empty;
        if (ex.InnerException != null)
            inner = ex.InnerException.ToString();
        //     logger.Error("Error in GetNotificationById function aperturenetdal " + ex.ToString() + " " + inner);
        return "";
Applies to: Rebex SFTP

1 Answer

0 votes
answered Oct 21, 2016 by Tomas Knopp (58,580 points)


SFTP and FTP/SSL are completely different file transfer protocols. See

Also there is no active or passive mode in SFTP protocol.

You probably are referring to FTP protocol.
In that case, just change your code from:

Sftp client = new Sftp();


Ftp client = new Ftp();

In FTP client the passive mode is default, so no need to set anything more.

commented Oct 21, 2016 by Tomas Knopp (58,580 points)
So just give it a try with the Ftp component and let us know if it works.