Question

The following code will throw an exception when i try to connect to a "write-only" ftp

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftp://...);

request.Credentials = new NetworkCredential("username", "password");

request.Method = WebRequestMethods.Ftp.UploadFile;

Stream ftpstream = request.GetRequestStream();

GetRequestStream() throws a "permission denied" exception since the framework implements the FTP commands as follows: - open - user - pwd

please any help ?

No correct solution

OTHER TIPS

Check out this thread.

Also, to avoid the PWD behind the scene you could use a .Net FTP client like edtFtpNet like this:

        var ftp = new FTPClient();
        ftp.BytesTransferred += new BytesTransferredHandler((o, e) => { Console.WriteLine("Remote Path: " + e.RemotePath + ", Remote File: " + e.RemoteFile + ", Bytes transfered: " + e.ByteCount); });
        ftp.TransferStartedEx += new TransferHandler((o, e) => { Console.WriteLine("FTP Transfer started!"); });
        ftp.TransferCompleteEx += new TransferHandler((o, e) => { Console.WriteLine("FTP Transfer completed!"); });

        try
        {
            ftp.RemoteHost = FTP_HOST;
            ftp.ConnectMode = FTPConnectMode.ACTIVE;
            ftp.Timeout = 120000;
            ftp.Connect();
            ftp.Login(FTP_USER, FTP_PWD);
            ftp.TransferType = FTPTransferType.BINARY;
            ftp.Put(GetBytes("file contents go here!"), Guid.NewGuid().ToString() + ".txt");
        }
        catch (Exception e)
        {
            Console.WriteLine("Error:" + e.ToString());
        }
        finally
        {
            ftp.Quit();
            Console.WriteLine("FTP Quit!");
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top