Upload files to a remote server

前端 未结 3 1313
梦如初夏
梦如初夏 2021-01-15 05:27

I need to upload files from my asp.net (C#) page residing in the web server to a remote server.

I managed to upload files to remote server from localhost using this

相关标签:
3条回答
  • 2021-01-15 05:33

    In FileUpload1.PostedFile.SaveAs(path), path is physical path of file, No Url. You must check:

    • is Physical folder Exsist?
    • is You have access to folder?

    if answer of both question is true check this code:

    string serverPath = @"\\xxx.xxx.xxx.xxx\Folder\";
    if (!System.IO.Directory.Exists(serverPath))
        System.IO.Directory.CreateDirectory(serverPath);
    
    FileUpload1.PostedFile.SaveAs(serverPath + FileUpload1.FileName);
    
    0 讨论(0)
  • 2021-01-15 05:52

    The account your application runs under must have write permissions to the folder you are trying to upload the file to: \\xx.xxx.xx.xx\Folder\. So you will have to configure the application pool in IIS to run under an account that will have sufficient permissions. Go to the application pool properties in the IIS management console where you will be able to specify an account to be used to run the application. By default it uses a built-in account which won't have any access to shared resources. Take a look at the following article which explains how to do so.

    0 讨论(0)
  • 2021-01-15 05:52

    You need a virtual directory on your webserver to upload to. In code you'll have to use Server.Mappath("virtual path") function to get its server path and then save to it.

    0 讨论(0)
提交回复
热议问题