如何将文件上传到我在weebly.com上的ftp
本文关键字:weebly com 上的 ftp 文件 | 更新日期: 2023-09-27 17:51:22
这就是他们所说的使用ftp:
http://www.ipage.com/controlpanel/FTP.bml
您可以使用Web创作工具构建网站,然后使用FTP程序将网页上传到您的iPage帐户。
要使用FTP客户端访问您的帐户,您需要使用FTP用户名和密码连接到FTP.newsexpressmedia.com。
这就是我现在尝试的方法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;
namespace ScrollLabelTest
{
class FtpFileUploader
{
static string ftpurl = "ftp://ftp.newsxpressmedia.com";
static string filename = @"c:'temp'test.txt";
static string ftpusername = "newsxpressmediacom";
static string ftppassword = "*****";
static string value;
public static void test()
{
try
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpurl);
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential(ftpusername, ftppassword);
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(@"c:'temp'test.txt");
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
response.Close();
}
catch(Exception err)
{
string t = err.ToString();
}
}
}
}
但我遇到了一个例外:
Stream requestStream = request.GetRequestStream();
例外:
The requested URI is invalid for this FTP command
完整的异常错误消息:
System.Net.WebException was caught
HResult=-2146233079
Message=The requested URI is invalid for this FTP command.
Source=System
StackTrace:
at System.Net.FtpWebRequest.GetRequestStream()
at ScrollLabelTest.FtpFileUploader.test() in e:'test'test'test'FtpFileUploader.cs:line 36
InnerException:
第36行是:
Stream requestStream = request.GetRequestStream();
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(
ftpUrl + "/" + Path.GetFileName(fileName));
您需要包括文件名。