メンバーが自分の写真を自分のプロフィールにアップロードできるように、Web サイトに機能を追加しています。私が抱えている問題は、自分のローカルホストを実行すると、FTP 機能が正常に動作することです。しかし、サイトを GoDaddy のサーバーに配置し、そこから FTP を試みても機能しません。私は得る
リモートサーバーに接続できません
これが私のコードです:
protected string savePath = Path.GetTempPath();
protected string saveThumbPath = Path.GetTempPath() + "/Thumb";
Guid g;
protected void UploadButton_Click(object sender, EventArgs e)
{
bool worked = false;
if (FileUploadControl.HasFile)
{
try
{
g = Guid.NewGuid();
string filename = Path.GetFileName(FileUploadControl.FileName);
Bitmap src = Bitmap.FromStream(FileUploadControl.PostedFile.InputStream) as Bitmap;
Bitmap thumb = Bitmap.FromStream(FileUploadControl.PostedFile.InputStream) as Bitmap;
// Resize the bitmap data
//Create the large image
Bitmap result = ProportionallyResizeBitmap(src, 800, 600);
//string saveName = Server.MapPath(savePath) + g + filename;
string saveName = savePath + g + filename;
result.Save(saveName, ImageFormat.Jpeg);
//Create the thumbnail
result = ProportionallyResizeBitmap(thumb, 200, 150);
//string saveThumbName = Server.MapPath(saveThumbPath) + g + filename;
string saveThumbName = saveThumbPath + g + filename;
result.Save(saveThumbName, ImageFormat.Jpeg);
StatusLabel.Text = "Upload status: File uploaded!";
worked = true;
Thumbholder.Value = "Thumb" + g + filename;
Photoholder.Value = g + filename;
// Get the object used to communicate with the server.
//If the specified proxy is an HTTP proxy. only the DownloadFile, ListDirectory and ListDirectoryDetails commands are supported
//get the object used to communicate with the server
System.Net.FtpWebRequest request = System.Net.WebRequest.Create("ftp://mydomain/newcorvetteclub/Images/" + g + filename) as System.Net.FtpWebRequest;
//this example assumes the FTP site uses anoymous login on
//NetWorkCredentials provides credentials for password-based authentication such as digest, basic, NTLM
request.Credentials = new System.Net.NetworkCredential("username", "password");
//Copy the contents of the file to the request stream
byte[] fileContents = null;
if (FileUploadControl.HasFile)
{
//fileContents = FileUploadControl.FileBytes;
fileContents = File.ReadAllBytes(saveName);
}
else
{
Response.Write("you need to provide a file");
return;
}
request.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
request.ContentLength = fileContents.Length;
//GetReequestStream: retrieves the stream used to upload data to an FTP server.
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
System.Net.FtpWebResponse response = request.GetResponse() as System.Net.FtpWebResponse;
//Response.Write("Upload file complete, status: " + response.StatusDescription);
response.Close();
request = System.Net.WebRequest.Create("ftp://mydomain/newcorvetteclub/Images/Thumb" + g + filename) as System.Net.FtpWebRequest;
request.Credentials = new System.Net.NetworkCredential("username", "password");
if (FileUploadControl.HasFile)
{
fileContents = File.ReadAllBytes(saveThumbName);
}
else
{
Response.Write("you need to provide a file");
return;
}
request.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
request.ContentLength = fileContents.Length;
//GetReequestStream: retrieves the stream used to upload data to an FTP server.
requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
response = request.GetResponse() as System.Net.FtpWebResponse;
//Response.Write("Upload file complete, status: " + response.StatusDescription);
もう 1 つの奇妙な点は、私の電子メール クライアントが同様のことを行っていることです。localhost を介して実行されている限り問題なく動作しますが、GoDaddy のサーバーから実行されるとタイムアウトします。どんな助けでも大歓迎です。