Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP Program

Status
Not open for further replies.

T111

Programmer
Jun 28, 2003
91
IE
Have a program that
1 - converts a EXCEL to a text file using vb.net, if no excel file exists then it creates an empty text file with correct name - current date and time. So my VB program first Shell's the vb.net program. A special shell that waits for the process to end before proceeding.
2 – FTP’s the text file to a certain location then receives the file back and sends an email about the result.

It always works when no excel file exists. It always works when run manually even if an excel file exists or not. However sometimes when scheduled and an excel file exists it might not work. When I receive the email saying it doesn’t work I run it manually and it works. It converts the files but doesn’t send it and every time I debug it - it always works.

Confused :-(.

Help please.
Thanks.
 
Can you be more specific about what part is not working and maybe post a bit of code showing that portion so we may better understand what is happening and maybe provide some help.
 
HI bmdb,

Thanks for you interest. I even created a setup.exe using installsheild express 5.0 so I could include the .net framework and all DLL etc. I have the program schedule every 2 hours. 2 hours and 10 mins ago it didn't work and 10 mins ago it did. With the same excel file to convert and send. Here is the code and there is allot of functions used if you need more code let me know, but it works every time I click it manually and when no file exists to convert.

I know that when it breaks the file is converted but not sent; one time I got the email before the file was sent. Maybe that’s just looked that way since the PC was so fast but I seen the outlook email notification ("Failed to send file") before I seen the file created that has to be sent. I was in the directory where the file has to be created send, and then deleted. Every time it breaks the file is converted and ready to be sent.

Thanks for your effort.

Private Sub Form_Load()
On Error GoTo Error_Handler

CurDates = Format(Date, "dd/mm/yyyy")
CurTime = Format(Now, "hh:mm:ss")

gsUser = "XXX" 'User ID to logon to FTP server.
gsPswd = "XXX" 'Password to logon to FTP server.

gsServer = " 'FTP server name.
gsLocalDir = App.Path 'Folder on local client holding files to FTP.
gsFTPDir = "XXX" 'Folder on FTP server to xfer files to/from

'Convert file by waiting for vb.net pgm to end
Dim retval As Long
retval = ExecCmd(App.Path & "\ExcelToCSV.exe")

'When error occurs it dosen't get this far
'Send the file
cmdSend_Click

'Recieve the file
cmdReceive_Click


'Reads the text file to get the filename that was sent e.g. "XXX_20040617153456.txt"
Dim SentFileName As String
SentFileName = GetFileName
If FileExist(App.Path & "\" & SentFileName) Then _
Kill (App.Path & "\" & SentFileName)
If FileExist(App.Path & "\NMB RECEIPT FILE.xls") Then _
Kill (App.Path & "\NMB RECEIPT FILE.xls")

'Open up outlook to notify the result of the program
EmailList "File Successfully Sent " & CurDates & " " & CurTime

If Not FileExist(App.Path & "\temp\" & SentFileName) Then GoTo Error_Handler

Beep
End

Error_Handler:
EmailList "File Not Sent " & CurDates & " " & CurTime
End
End Sub
 
Hi T111,

It sounds like the execcmd routine is running the same time as the convert routine.

Here is a routine I use to insure the routine waits for execution to end.

Public Function ExecCmd(cmdline$) As Long
'
' this routine executes the program and
' waits for that program to end before continuing
'
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim lRet As Long
'
start.cb = Len(start) ' Initialize the STARTUPINFO structure:
lRet = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc) ' Start the shelled application:
lRet = WaitForSingleObject(proc.hProcess, INFINITE) ' Wait for the shelled application to finish:
Call GetExitCodeProcess(proc.hProcess, lRet)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
'
ExecCmd = lRet
'
End Function

Hope this is helpful.
 
If this is a VB.NET problem then it's off topic in this (VB6) forum. You'll do better in forum796

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Hi Brian,

I am already using the ExecCmd function. I think I solved the problem a work around at least. I told the program that if it failed go back and start over again and it worked. Weird i know but it works. Thanks for you help anyway.

All the code is for VB; my problem is in a vb program so this is not a vb.net problem johnwm?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top