I wrote this program to do a simple ftp upload. Its always an audio file, and if its not an mp3 I need to convert it. The only other format is .au files, and the error is only thrown when its not an mp3 to begin with. If I were to run the program again, only this time with the newly converted mp3 file everything works fine.
What am I doing wrong here? It was working just fine not to long ago and it seems like over night it decided to break?
The error I get:
System.Net.WebException: An exception occurred during a WebClient request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at System.Net.FtpWebRequest.EndGetRequestStream(IAsyncResult asyncResult)
at System.Net.WebClient.UploadBitsRequestCallback(IAsyncResult result)
--- End of inner exception stack trace ---
at Microsoft.VisualBasic.MyServices.Internal.WebClientCopy.UploadFile(String sourceFileName, Uri address)
at Microsoft.VisualBasic.Devices.Network.UploadFile(String sourceFileName, Uri address, ICredentials networkCredentials, Boolean showUI, Int32 connectionTimeout, UICancelOption onUserCancel)
at Microsoft.VisualBasic.Devices.Network.UploadFile(String sourceFileName, String address, String userName, String password, Boolean showUI, Int32 connectionTimeout, UICancelOption onUserCancel)
at ftp_uploader.frm_Main.do_work()
The Code :
Thanks for the help!
Nick
What am I doing wrong here? It was working just fine not to long ago and it seems like over night it decided to break?
The error I get:
System.Net.WebException: An exception occurred during a WebClient request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at System.Net.FtpWebRequest.EndGetRequestStream(IAsyncResult asyncResult)
at System.Net.WebClient.UploadBitsRequestCallback(IAsyncResult result)
--- End of inner exception stack trace ---
at Microsoft.VisualBasic.MyServices.Internal.WebClientCopy.UploadFile(String sourceFileName, Uri address)
at Microsoft.VisualBasic.Devices.Network.UploadFile(String sourceFileName, Uri address, ICredentials networkCredentials, Boolean showUI, Int32 connectionTimeout, UICancelOption onUserCancel)
at Microsoft.VisualBasic.Devices.Network.UploadFile(String sourceFileName, String address, String userName, String password, Boolean showUI, Int32 connectionTimeout, UICancelOption onUserCancel)
at ftp_uploader.frm_Main.do_work()
The Code :
VB.NET:
Dim strStartupArguments() As String
Public filename, filepath As String
Sub do_work()
If My.Computer.FileSystem.FileExists(filepath & filename) = True Then
Try
Dim source_file As String = filepath & filename
Dim ftp_file As String = "ftp://www.marcomtechnologies.com/audio_upload/" & filename
My.Computer.Network.UploadFile(source_file, ftp_file, username, password, True, 30000, FileIO.UICancelOption.ThrowException)
Catch ex As Exception
If Strings.Left(ex.ToString, 28) = "System.InvalidCastException:" Then
do_work() ' The Do:Loop code earlier when I converted the .au file that tests for the file to exist doesn't know that the file is done being
' converted, this will be thrown if the file isn't done, so I just keep calling the sub. I think this is what is causing the problem?
Else
MsgBox("There was an ftp uploader error : " & vbCrLf & vbCrLf & ex.ToString & vbCrLf & vbCrLf & "Please try to upload the file again!")
End If
End Try
End If
End Sub
Private Sub frm_Main_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
strStartupArguments = System.Environment.GetCommandLineArgs
If strStartupArguments.Count > 1 Then
Dim tmp_cmds() As String = Split(strStartupArguments(1), "|||")
filepath = Strings.Replace(tmp_cmds(0), "|", " ")
filename = tmp_cmds(1)
If Strings.LCase(Strings.Right(filename, 3)) <> "mp3" Then
MsgBox("not an mp3!")
Dim loc_of_dot As Integer = InStr(filename, ".")
Dim name_no_ext As String = Strings.Left(filename, loc_of_dot - 1)
Shell(Application.StartupPath & "\sox.exe " & """" & filepath & filename & """" & " " & """" & filepath & name_no_ext & ".mp3" & """", AppWinStyle.MaximizedFocus)
Do While My.Computer.FileSystem.FileExists(filepath & name_no_ext & ".mp3") = False
Loop ' Have to wait till the file is there.
filename = name_no_ext + ".mp3"
End If
do_work()
Else
MsgBox("No file Submitted!")
End
End If
End
End Sub
Thanks for the help!
Nick