|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Ftp file overwrite warningthe code, I got it from MS. This is also not the entire code. It works fine, except that I get no warning if I am about to overwrite a file already on the FTP site. Can someone show me how to pop up a warning if this situation occurs? --Tony-- __________________________________________________________________ If hFile = 0 Then ErrorOut Err.LastDllError, "FtpOpenFile" Exit Sub End If Open Text4 For Binary Access Read As #1 Size = LOF(1) For j = 1 To Size \ 100 Get #1, , Data If (InternetWriteFile(hFile, Data(0), 100, Written) = 0) Then ErrorOut Err.LastDllError, "InternetWriteFile" Exit Sub End If DoEvents Sum = Sum + 100 Label7.Caption = Str(Sum) Next j Get #1, , Data If (InternetWriteFile(hFile, Data(0), Size Mod 100, Written) = 0) Then ErrorOut Err.LastDllError, "InternetWriteFile" Exit Sub End If Tony <T***@discussions.microsoft.com> wrote:
> I am using the code below to transfer a file to an FTP site. I did not write Honest suggestion? Rewrite the code "in your own words." Come to terms with what > the code, I got it from MS. This is also not the entire code. It works > fine, except that I get no warning if I am about to overwrite a file already > on the FTP site. Can someone show me how to pop up a warning if this > situation occurs? it's doing. If you can't get there, you won't get where you want to go. But if you do understand what that code is doing, you'd realize that before you ever ran it you'd want to do an FtpFileExists type of check on the destination. I agree with Karl, but don't follow the MS example here and use hard-coded
files numbers (e.g. #1). Always use FreeFile() to allow the next available one and store it in an Integer variable Tony Proctor "Karl E. Peterson" <k***@mvps.org> wrote in message But if younews:eJxldt1kHHA.3484@TK2MSFTNGP02.phx.gbl... > Tony <T***@discussions.microsoft.com> wrote: > > I am using the code below to transfer a file to an FTP site. I did not write > > the code, I got it from MS. This is also not the entire code. It works > > fine, except that I get no warning if I am about to overwrite a file already > > on the FTP site. Can someone show me how to pop up a warning if this > > situation occurs? > > Honest suggestion? Rewrite the code "in your own words." Come to terms with what > it's doing. If you can't get there, you won't get where you want to go. Show quoteHide quote > do understand what that code is doing, you'd realize that before you ever ran it > you'd want to do an FtpFileExists type of check on the destination. > -- > .NET: It's About Trust! > http://vfred.mvps.org > >
Show quote
Hide quote
"Karl E. Peterson" wrote: thanks for your suggestion, but this type of coding is way beyond me. I am > Tony <T***@discussions.microsoft.com> wrote: > > I am using the code below to transfer a file to an FTP site. I did not write > > the code, I got it from MS. This is also not the entire code. It works > > fine, except that I get no warning if I am about to overwrite a file already > > on the FTP site. Can someone show me how to pop up a warning if this > > situation occurs? > > Honest suggestion? Rewrite the code "in your own words." Come to terms with what > it's doing. If you can't get there, you won't get where you want to go. But if you > do understand what that code is doing, you'd realize that before you ever ran it > you'd want to do an FtpFileExists type of check on the destination. > -- > ..NET: It's About Trust! > http://vfred.mvps.org > > > Karl, good with "local" VB, but I am not proficient with Internet coding and I haven't been able to find any good references or examples to learn from. --Tony-- Tony <T***@discussions.microsoft.com> wrote:
Show quoteHide quote > "Karl E. Peterson" wrote: Here's the jist of it:>> Tony <T***@discussions.microsoft.com> wrote: >>> I am using the code below to transfer a file to an FTP site. I did not write >>> the code, I got it from MS. This is also not the entire code. It works >>> fine, except that I get no warning if I am about to overwrite a file already >>> on the FTP site. Can someone show me how to pop up a warning if this >>> situation occurs? >> >> Honest suggestion? Rewrite the code "in your own words." Come to terms with >> what it's doing. If you can't get there, you won't get where you want to go. >> But if you do understand what that code is doing, you'd realize that before you >> ever ran it you'd want to do an FtpFileExists type of check on the destination. > > thanks for your suggestion, but this type of coding is way beyond me. I am > good with "local" VB, but I am not proficient with Internet coding and I > haven't been able to find any good references or examples to learn from. Public Function FtpFileExists(ByVal Server As String, ByVal UrlPath As String, Optional UserName As String = "", Optional Password As String = "") As Boolean Dim hInetSess As Long Dim hInetConnect As Long Dim hInetFile As Long Dim wfd As WIN32_FIND_DATA Const Agent As String = "VBPJ Pro" ' Open an internet session hInetSess = InternetOpen(Agent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0&) If hInetSess Then ' Connect to host hInetConnect = InternetConnect(hInetSess, Server, INTERNET_DEFAULT_FTP_PORT, UserName, Password, INTERNET_SERVICE_FTP, 0, 0) If hInetConnect Then ' Search for matching filespec hInetFile = FtpFindFirstFile(hInetConnect, UrlPath, wfd, INTERNET_FLAG_RELOAD, 0) If hInetFile Then FtpFileExists = True Call InternetCloseHandle(hInetFile) Else Debug.Print "FtpFindFirstFile Error: " & _ WinInetErrorText(Err.LastDllError) End If Call InternetCloseHandle(hInetConnect) Else Debug.Print "InternetConnect Error: " & _ WinInetErrorText(Err.LastDllError) End If Call InternetCloseHandle(hInetSess) Else Debug.Print "InternetOpen Error: " & _ WinInetErrorText(Err.LastDllError) End If End Function You can grab the whole enchilada, once my server comes back online (disk corruption <sigh>), here: http://vb.mvps.org/samples/FtpExists Thanks Karl.... this gives me something to work with!
-=Tony=- Show quoteHide quote "Karl E. Peterson" wrote: > Tony <T***@discussions.microsoft.com> wrote: > > "Karl E. Peterson" wrote: > >> Tony <T***@discussions.microsoft.com> wrote: > >>> I am using the code below to transfer a file to an FTP site. I did not write > >>> the code, I got it from MS. This is also not the entire code. It works > >>> fine, except that I get no warning if I am about to overwrite a file already > >>> on the FTP site. Can someone show me how to pop up a warning if this > >>> situation occurs? > >> > >> Honest suggestion? Rewrite the code "in your own words." Come to terms with > >> what it's doing. If you can't get there, you won't get where you want to go. > >> But if you do understand what that code is doing, you'd realize that before you > >> ever ran it you'd want to do an FtpFileExists type of check on the destination. > > > > thanks for your suggestion, but this type of coding is way beyond me. I am > > good with "local" VB, but I am not proficient with Internet coding and I > > haven't been able to find any good references or examples to learn from. > > Here's the jist of it: > > Public Function FtpFileExists(ByVal Server As String, ByVal UrlPath As String, > Optional UserName As String = "", Optional Password As String = "") As Boolean > Dim hInetSess As Long > Dim hInetConnect As Long > Dim hInetFile As Long > Dim wfd As WIN32_FIND_DATA > Const Agent As String = "VBPJ Pro" > > ' Open an internet session > hInetSess = InternetOpen(Agent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, > vbNullString, 0&) > If hInetSess Then > ' Connect to host > hInetConnect = InternetConnect(hInetSess, Server, > INTERNET_DEFAULT_FTP_PORT, UserName, Password, INTERNET_SERVICE_FTP, 0, 0) > If hInetConnect Then > ' Search for matching filespec > hInetFile = FtpFindFirstFile(hInetConnect, UrlPath, wfd, > INTERNET_FLAG_RELOAD, 0) > If hInetFile Then > FtpFileExists = True > Call InternetCloseHandle(hInetFile) > Else > Debug.Print "FtpFindFirstFile Error: " & _ > WinInetErrorText(Err.LastDllError) > End If > Call InternetCloseHandle(hInetConnect) > Else > Debug.Print "InternetConnect Error: " & _ > WinInetErrorText(Err.LastDllError) > End If > Call InternetCloseHandle(hInetSess) > Else > Debug.Print "InternetOpen Error: " & _ > WinInetErrorText(Err.LastDllError) > End If > End Function > > You can grab the whole enchilada, once my server comes back online (disk corruption > <sigh>), here: > > http://vb.mvps.org/samples/FtpExists > > -- > ..NET: It's About Trust! > http://vfred.mvps.org > > > |
|||||||||||||||||||||||