Hi,
i try to upload a File (/system/Database.xml) to my FTP-Server. i use this
code:
{
public void Main()
{
string ftplocation = "ftp://[email protected]/htdocs";
string file = Android.OS.Environment.RootDirectory +
Java.IO.File.Separator + "Datenbank.xml";
string user = "usrname";
string password = "passwrd";
UploadToFTP(ftplocation, file, user, password);
}
public void UploadToFTP(String inFTPServerAndPath, String
inFullPathToLocalFile, String inUsername, String inPassword)
{
// Get the local file name: C:\Users\Rhyous\Desktop\File1.zip
// and get just the filename: File1.zip. This is so we can add
it
// to the full URI.
String filename = "Datenbank.xml";
// Open a request using the full URI, c/file.ext
FtpWebRequest request =
(FtpWebRequest)FtpWebRequest.Create(inFTPServerAndPath + "/" + filename);
// Configure the connection request
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(inUsername,
inPassword);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
// Create a stream from the file
FileStream stream = File.OpenRead(inFullPathToLocalFile);
byte[] buffer = new byte[stream.Length];
// Read the file into the a local stream
stream.Read(buffer, 0, buffer.Length);
// Close the local stream
stream.Close();
// Create a stream to the FTP server
Stream reqStream = request.GetRequestStream();
// Write the local stream to the FTP stream
// 2 bytes at a time
int offset = 0;
int chunk = (buffer.Length > 2048) ? 2048 : buffer.Length;
while (offset < buffer.Length)
{
reqStream.Write(buffer, offset, chunk);
offset += chunk;
chunk = (buffer.Length - offset < chunk) ? (buffer.Length -
offset) : chunk;
}
// Close the stream to the FTP server
reqStream.Close();
}
}
there is no error message but the file is not on the FTP server :( do
anyone know how to do it?
--
View this message in context:
http://mono-for-android.1047100.n5.nabble.com/FTP-Upload-tp5711365.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid