File upload on FTP server not working

gpuk360

I am trying to upload a file to my ftp server. Unfortunately, the upload method seems to work but does not upload my selected file. Please, see my code below:

public void UploadFileToFTP(string source)
    {
        try
        {
            FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create("ftp://xxx.bplaced.net/Test");
            ftp.Credentials = new NetworkCredential("BN", "PW");

            ftp.KeepAlive = true;
            ftp.UseBinary = true;
            ftp.Method = WebRequestMethods.Ftp.UploadFile;

            FileStream fs = File.OpenRead(source);
            byte[] buffer = new byte[fs.Length];
            fs.Read(buffer, 0, buffer.Length);
            fs.Close();

            Stream ftpstream = ftp.GetRequestStream();
            ftpstream.Write(buffer, 0, buffer.Length);
            ftpstream.Close();

            MessageBox.Show("Upload successful!");
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

public void button_Upload_Click(object sender, RoutedEventArgs e)
    {
        string sourcefilepath = @"C:\Users\MyPC\Desktop\Test\Texts\New.html";
        UploadFileToFTP(sourcefilepath);
    }

Please see this screenshot: What is meant by "Is a directory"?

SCREENSHOT

Error is clear: Problem fixed.

Mat J

You should call the GetResponse() method to actually send the ftp request. You have only prepared the request to be sent in your code.

To quote MSDN,

GetResponse causes a control connection to be established, and might also create a data connection. GetResponse blocks until the response is received. To prevent this, you can perform this operation asynchronously by calling the BeginGetResponse and EndGetResponse methods in place of GetResponse.

So, After writing the file contents, call

ftp.GetResponse()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

File does not upload to FTP server

From Dev

Ajax upload a file from browser to FTP server

From Dev

Upload a file to an FTP server from a string or stream

From Dev

How can i upload a file into a ftp server?

From Dev

Upload file to FTP Server using Indy

From Dev

Upload a file to a server using FTP using php

From Dev

Upload file to remote FTP server errors

From Dev

Ajax upload a file from browser to FTP server

From Dev

How can i upload a file into a ftp server?

From Dev

Upload file to FTP Server using Indy

From Dev

How to upload file to remote FTP Server in grails

From Dev

How to upload file to FTP Server in grails

From Dev

not able to upload file to server via ftp/ cpanel

From Dev

how to upload a pdf file to ftp server using file upload controller?

From Dev

PowerShell FTP upload not working - Creating zero byte file

From Dev

PowerShell FTP upload not working - Creating zero byte file

From Dev

Upload folder to FTP server

From Dev

php multiple file upload not working at server

From Dev

Codeigniter File Upload Not Working On Live Server

From Dev

image file upload not working on wamp server

From Dev

Create a CSV File and Upload to Server via FTP in MVC / C#

From Dev

How to upload a sqlite db file to ftp server from android program

From Dev

Phonegap:Get the file from sdcard and upload it to the FTP Server in android

From Dev

How do I upload a file to an FTP server using a batch script?

From Dev

How to upload a sqlite db file to ftp server from android program

From Dev

Create a CSV File and Upload to Server via FTP in MVC / C#

From Dev

Dynamic Upload file to FTP

From Dev

How to upload file to remote FTP server using Varien_Io_Ftp in Magento?

From Dev

How to upload file to remote FTP server using Varien_Io_Ftp in Magento?

Related Related

  1. 1

    File does not upload to FTP server

  2. 2

    Ajax upload a file from browser to FTP server

  3. 3

    Upload a file to an FTP server from a string or stream

  4. 4

    How can i upload a file into a ftp server?

  5. 5

    Upload file to FTP Server using Indy

  6. 6

    Upload a file to a server using FTP using php

  7. 7

    Upload file to remote FTP server errors

  8. 8

    Ajax upload a file from browser to FTP server

  9. 9

    How can i upload a file into a ftp server?

  10. 10

    Upload file to FTP Server using Indy

  11. 11

    How to upload file to remote FTP Server in grails

  12. 12

    How to upload file to FTP Server in grails

  13. 13

    not able to upload file to server via ftp/ cpanel

  14. 14

    how to upload a pdf file to ftp server using file upload controller?

  15. 15

    PowerShell FTP upload not working - Creating zero byte file

  16. 16

    PowerShell FTP upload not working - Creating zero byte file

  17. 17

    Upload folder to FTP server

  18. 18

    php multiple file upload not working at server

  19. 19

    Codeigniter File Upload Not Working On Live Server

  20. 20

    image file upload not working on wamp server

  21. 21

    Create a CSV File and Upload to Server via FTP in MVC / C#

  22. 22

    How to upload a sqlite db file to ftp server from android program

  23. 23

    Phonegap:Get the file from sdcard and upload it to the FTP Server in android

  24. 24

    How do I upload a file to an FTP server using a batch script?

  25. 25

    How to upload a sqlite db file to ftp server from android program

  26. 26

    Create a CSV File and Upload to Server via FTP in MVC / C#

  27. 27

    Dynamic Upload file to FTP

  28. 28

    How to upload file to remote FTP server using Varien_Io_Ftp in Magento?

  29. 29

    How to upload file to remote FTP server using Varien_Io_Ftp in Magento?

HotTag

Archive