• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 587
  • Last Modified:

Inet Question

I'm using Inet to FTP a file, this all works good but i want it to overwrite the file if its already there on the server. here's some of my code. Thanks

Inet1.AccessType = icUseDefault
Inet1.Protocol = icFTP
Inet1.RemoteHost = "server.com"
Inet1.RemotePort = "21"
Inet1.Password = "pass"
Inet1.UserName = "user"
Inet1.RequestTimeout = "60"

strLocal = file.Text

strRemote = "/usr/home/public_html/upload/" & upfilestr
Inet1.Execute , "PUT """ & strLocal & """ " & strRemote
0
jmingo
Asked:
jmingo
  • 7
  • 7
1 Solution
 
Jeremy DaleySenior DeveloperCommented:
i've been trying to accomplish the same task only with the "GET" command, but it simply won't overwrite.
i would suggest just running a procedure:

'Declare your variables
Dim strRemote as String
Dim strLocal as String

strRemote = "/usr/home/public_html/upload/" & upfilestr
'Delete the original file before you PUT the new file in
Inet1.Execute , "DELETE " & strRemote
Do While Inet1.StillExecuting = True
     DoEvents
Loop

strLocal = file.Text
Inet1.Execute , "PUT """ & strLocal & """ " & strRemote
Do While Inet1.StillExecuting = True
     DoEvents
Loop

'Close your FTP connection if necessary
Inet1.Execute , "CLOSE"
Do While Inet1.StillExecuting = True
     DoEvents
Loop

(delete the file yourself, and just slip in the new file with your "PUT" command)
an overwrite would do pretty much the same thing.

**Also, instead of using a quotation mark, use Chr(34) instead. ie:
"PUT " & Chr(34) & strLocal & Chr(34) & " " & Chr(34) & strRemote & Chr(34)

good luck with that,
jeremy
0
 
jmingoAuthor Commented:
i think i'm getting close with that code daleyjem.

when the file is not there i get this error

ErrorCode: 12003: 550 No such file.

i thought i fixed this by doing this, but doesn't work. any ideas. thanks

Private Sub Inet2_StateChanged(ByVal State As Integer)

Select Case State

Case icError ' 11

If err.Number = 12003 Then
err.Clear
Resume Next
Else
MsgBox "ErrorCode: " & Inet2.ResponseCode & " : " & Inet2.ResponseInfo, vbCritical
End If

End Select

End Sub
0
 
Jeremy DaleySenior DeveloperCommented:
using quotations within quotations is not correct syntax with VB... the quote that you are trying to enclose in the quotes is essentially becoming just the ending quotation mark to the first one. that could be where some of your problem is arising.

like i said... use the Chr(34). this is the ASCII code for a quotation mark.
and if you put your whole file string into a variable:
ie.
fileStr = "PUT " & Chr(34) & strLocal & Chr(34) & " " & Chr(34) & strRemote & Chr(34)

... you can always do:
debug.Print fileStr

...to make sure that your string is going in right. it is also important that you declare your variable as a string. Declaring your strings may not ALWAYS be necessary, but in this case it is.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
jmingoAuthor Commented:
all my strings are declared  and i changed this

Inet2.Execute , "PUT " & Chr(34) & strLocal & Chr(34) & " " & Chr(34) & strRemote & Chr(34)

it only happens when i try and delete the file i believe.


0
 
jmingoAuthor Commented:
it only happens when i try and delete the file and there's no file there to delete i believe.
0
 
jmingoAuthor Commented:
ok i have a problem here, maybe you can help me. i go to a webpage once it completes the upload to the server by doing a StateChanged, but i think this get fired when it finishes the delete process. What can i do so that the webpage gets loaded after everything is done??

Private Sub Inet2_StateChanged(ByVal State As Integer)

Select Case State
Case icResponseCompleted
WebBrowser3.Navigate ("http://server.com")

....



0
 
jmingoAuthor Commented:
should i take it out of statechange, and make it do something like this??

Upload 'function that has all the inet stuff

WebBrowser3.Navigate ("http://server.com")


Would i put a DoEvents between these maybe, or should the code you gave me finish up all the Inet commands before it loads the webpage???

Thanks
0
 
Jeremy DaleySenior DeveloperCommented:
not to be picky or stingy or what have you... but 25 points for this question?
0
 
Jeremy DaleySenior DeveloperCommented:
and you're sure the new file is being upload? have you looked at the "date modified" of the file to make sure it is the most recent file?

i think what you are doing seems right, but even though your page is navigating after an upload, either the file isn't actually being uploaded... or you may just have to just refresh your browser.
0
 
jmingoAuthor Commented:
i will up the points a bit because some of it is a bit out of the realm of the initial question.

i have to have it wait until the upload is complete. i think its working now, but need to test it out more.

how do i look at the date modified??

thanks

0
 
Jeremy DaleySenior DeveloperCommented:
well, if you use a program like SmartFTP, you can always use that program to verify. it has a "Date" column that you can see the date it was last dealt with.

with that... run your upload from your program and then ftp using SmartFTP to see if the date and time are correct. if not... you're file isn't being uploaded in the first place. if so, your website should show that new file. like i said, you may need to refresh your page.

if you're uploading something such as a macromedia flash file, you'll have to clear your internet explorer'r file cache (Tools --> Options --> Delete Files) and check offline content as well... and then refresh your page.

keep me posted on your progress..
0
 
jmingoAuthor Commented:
it has to be in my program, no 3rd party software.
0
 
Jeremy DaleySenior DeveloperCommented:
i know that... i'm just saying to use the third party software to find the date modified after you upload the file... to make sure that it is in fact being uploaded. that way you know your code is uploading right. then once it does, you won't have to use it again. it's only for testing purposes.
0
 
Jeremy DaleySenior DeveloperCommented:
any progress on this matter?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now