Hi, Usually I try to do searches to get my answers instead of asking questions and so far I have been getting by, but now I need to ask a question. I'm trying to connect to the FTP server that is in this thread https://www.b4x.com/android/forum/t...plemented-with-socket-and-asyncstreams.74320/
Using a visual basic desktop app. Basically what I am trying to do is copy a database file from a device to the PC then sync with it from a desktop app and then copy it back to the device. I figured FTP is an easy and reliable way to do this. I have tried different URL syntax but it is still unable to connect.
I figured this syntax would work ftp://192.168.2.1:15162/ that is, using the URL and port number but everything I tried doesn't work. I've set passive mode to true and false but it none had any effect.
Here is the code I'm using in visual basic
I'm using a text box to enter the url and an openfiledialog for the file to send and then passing the arguments to the subroutine.
Any help would be appreciated.
Using a visual basic desktop app. Basically what I am trying to do is copy a database file from a device to the PC then sync with it from a desktop app and then copy it back to the device. I figured FTP is an easy and reliable way to do this. I have tried different URL syntax but it is still unable to connect.
I figured this syntax would work ftp://192.168.2.1:15162/ that is, using the URL and port number but everything I tried doesn't work. I've set passive mode to true and false but it none had any effect.
Here is the code I'm using in visual basic
B4X:
Private Sub FtpUploadFile(ByVal filetoupload As String, ByVal ftpuri As String, ByVal ftpusername As String, ByVal ftppassword As String)
' Create a web request that will be used to talk with the server and set the request method to upload a file by ftp.
Dim ftpRequest As FtpWebRequest = DirectCast(WebRequest.Create(ftpuri), FtpWebRequest)
'(CType(WebRequest.Create(ftpuri), FtpWebRequest)
Try
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile
ftpusername = "Test"
ftppassword = "test"
ftpRequest.UsePassive = True
' Confirm the Network credentials based on the user name and password passed in.
ftpRequest.Credentials = New NetworkCredential(ftpusername, ftppassword)
' Read into a Byte array the contents of the file to be uploaded
Dim bytes() As Byte = System.IO.File.ReadAllBytes(filetoupload)
' Transfer the byte array contents into the request stream, write and then close when done.
ftpRequest.ContentLength = bytes.Length
Using UploadStream As Stream = ftpRequest.GetRequestStream()
UploadStream.Write(bytes, 0, bytes.Length)
UploadStream.Close()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Sub
End Try
MessageBox.Show("Process Complete")
End Sub
Private Sub FTPDownloadFile(ByVal downloadpath As String, ByVal ftpuri As String, ByVal ftpusername As String, ByVal ftppassword As String)
'Create a WebClient.
Dim request As New WebClient()
ftpusername = "Test"
ftppassword = "test"
' Confirm the Network credentials based on the user name and password passed in.
request.Credentials = New NetworkCredential(ftpusername, ftppassword)
'Read the file data into a Byte array
Dim bytes() As Byte = request.DownloadData(ftpuri)
Try
' Create a FileStream to read the file into
Dim DownloadStream As FileStream = IO.File.Create(downloadpath)
' Stream this data into the file
DownloadStream.Write(bytes, 0, bytes.Length)
' Close the FileStream
DownloadStream.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Sub
End Try
MessageBox.Show("Process Complete")
End Sub
I'm using a text box to enter the url and an openfiledialog for the file to send and then passing the arguments to the subroutine.
Any help would be appreciated.