内部にFTPサーバーとDATAをアップロードする必要があります。c#FTPサーバー内にバイト[]をアップロード
ファイルとFTPをアップロードする方法については、stackoverflowの投稿に続いてすべてが動作します。
アップロードを改善しようとしています。
DATAを収集し、FILEに書き込んだ後、FTP内でファイルをアップロードすると、DATAを収集してローカルファイルを作成せずにアップロードします。
起こる何今string uri = "ftp://" + ftpServerIp + "/" + fileToUpload.Name;
System.Net.FtpWebRequest reqFTP;
// Create FtpWebRequest object from the Uri provided
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIp + "/" + fileToUpload.Name));
// Provide the WebPermission Credintials
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
// By default KeepAlive is true, where the control connection is not closed after a command is executed.
reqFTP.KeepAlive = false;
// Specify the command to be executed.
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
// Specify the data transfer type.
reqFTP.UseBinary = true;
byte[] messageContent = Encoding.ASCII.GetBytes(message);
// Notify the server about the size of the uploaded file
reqFTP.ContentLength = messageContent.Length;
int buffLength = 2048;
// Stream to which the file to be upload is written
Stream strm = reqFTP.GetRequestStream();
// Write Content from the file stream to the FTP Upload Stream
int total_bytes = (int)messageContent.Length;
while (total_bytes > 0)
{
strm.Write(messageContent, 0, buffLength);
total_bytes = total_bytes - buffLength;
}
strm.Close();
は以下の通りです:
は、私は次の操作を行い、これを達成するために- iは、ファイルが作成されたサーバー
- に接続しているクライアントを参照してください
- データが転送されない
- ある時点でスレッドが終了し、接続が閉じられる
- アップロードしたファイルが空であるかどうかを調べると
私が転送したいDATAはSTRING TYPEです。そのため、私はbyte []を行います。messageContent = Encoding.ASCII.GetBytes(message);
何が間違っていますか?
さらに:ASCII.GetBytesで日付をエンコードすると、リモートサーバー上にTEXTファイルまたはいくつかのバイトを持つファイルがありますか?
while (total_bytes > 0)
{
strm.Write(messageContent, 0, buffLength);
total_bytes = total_bytes - buffLength;
}
、変更する必要があります:
は、私がコードで参照
STRM:あなたはチャンクでデータを書き込む必要がある場合は
は、アレイ内のオフセットを追跡する必要があります.Write(messageContent、0、messageContent.lenght);解決策です。ちょうどこれのように私は一度にすべてのファイルを書き込むだろうと私は巨大なファイルで何が起こるか知りません。 – NoobTom