誰かが以下のコードを見て、私が間違っていることを教えてください。私はちょうど円を描いています、、、どんなポインタでも大歓迎です
public class FtpWebRequestUtil
{
private static string RemoteHost;
private static string RemoteFtpPath;
public static NetworkCredential Credential = new NetworkCredential();
public FtpWebRequestUtil()
{
}
public FtpWebRequestUtil(string RemoteAddress, string RemotePath, string RemoteUser, string RemotePwd)
{
Credential.UserName = RemoteUser;
Credential.Password = RemotePwd;
RemoteHost = RemoteAddress;
RemoteFtpPath = RemotePath;
}
public string UploadFile(string localFilePath)
{
int startTime = Environment.TickCount;
// Console.WriteLine("Uploading File " + localFilePath);
try
{
FileInfo localFile = new FileInfo(localFilePath); //e.g.: c:\\Test.txt
byte[] buf = new byte[2048];
int iWork;
string remoteFile = "ftp://" + RemoteHost + "/" + RemoteFtpPath + "/" + localFile.Name;
FtpWebRequest req = (FtpWebRequest) FtpWebRequest.Create(remoteFile);
// req.Proxy =
req.Credentials = Credential;
// FtpWebRequest req = (FtpWe
req.UseBinary = true;
req.KeepAlive = true;
req.Method = WebRequestMethods.Ftp.UploadFile;
StreamWriter myStreamWriter = new StreamWriter(req.GetRequestStream());
myStreamWriter.Write(new StreamReader("TestFiles\\" + localFile.Name).ReadToEnd());
myStreamWriter.Close();
FtpWebResponse myFtpWebResponse = (FtpWebResponse) req.GetResponse();
Console.WriteLine("Upload File Complete, status: " + myFtpWebResponse.StatusDescription);
myFtpWebResponse.Close();
return "SUCCESS";
}
catch (Exception ex)
{
Console.WriteLine("There was an error connecting to the FTP Server.");
Console.WriteLine(ex.Message);
throw ex;
}
Console.WriteLine("Time taken for downloading file is " + (Environment.TickCount - startTime).ToString());
return "FAILURE";
}
************************ *********************************
FtpWebRequestUtil ftpClient = new FtpWebRequestUtil(FtpUrl, InputFolder, FtpUser, FtpPassword);
try
{
Thread.Sleep(5000);
ftpClient.UploadFile(UploadingFileName);
}
catch (Exception exception)
{
Assert.Fail(exception.Message);
}
finally
{
ftpClient = null;
}
}
}