FTP access
FTP access
I think I am missing something... I know there is an example of an FTP server, but what would you have to do to connect to ANOTHER ftp server through PureBasic? All I need is a simple user/password login and upload/download system for my program, but I havent found any examples on how to actually access another server... any help?
Search is your friend 
It might take you to something like this...
viewtopic.php?t=8692&highlight=ftp
which will also point you to...
http://www.reelmediaproductions.com/purebasic
(which also had a search at the top right of the page so just type ftp inthere also)
Enjoy !!
ps. Personally I find it easiest to just use Windows API commands for FTP but it is also quite simple to write your own in PureBasic.

It might take you to something like this...
viewtopic.php?t=8692&highlight=ftp
which will also point you to...
http://www.reelmediaproductions.com/purebasic
(which also had a search at the top right of the page so just type ftp inthere also)
Enjoy !!
ps. Personally I find it easiest to just use Windows API commands for FTP but it is also quite simple to write your own in PureBasic.
Heya, kenmo.
Not sure if I'm on the same wavelength, but:
If you're talking server to server then would an automated client on the one server do the job? Or automated file-sharing?
If you're looking for clients, found some on one of these two sites (links courtesy of freak):
http://www.purearea.net/ (download the code snippets zip)
http://www.reelmediaproductions.com/pb/
Maybe on both - I have just been downloading heaps of stuff. Also found something called FTPxchg on one of the sites, it looks pretty awesome in theory and shouldn't be hard to automate, although there is a prob with a structure so I can't say for sure.
And - If I missed the point completely, apologies!
(A real expert will be along shortly to sort things out.)
EDIT:
The expert was faster! See above!
Not sure if I'm on the same wavelength, but:
If you're talking server to server then would an automated client on the one server do the job? Or automated file-sharing?
If you're looking for clients, found some on one of these two sites (links courtesy of freak):
http://www.purearea.net/ (download the code snippets zip)
http://www.reelmediaproductions.com/pb/
Maybe on both - I have just been downloading heaps of stuff. Also found something called FTPxchg on one of the sites, it looks pretty awesome in theory and shouldn't be hard to automate, although there is a prob with a structure so I can't say for sure.
And - If I missed the point completely, apologies!
(A real expert will be along shortly to sort things out.)

EDIT:
The expert was faster! See above!

Haha, well Im not sure what you mean either... Basically I want to edit an online file from PB and I figured the way to do it would be download it, edit it, and then upload it... probably using FTP commands. Imagine like a high score list, and if you get a high score you can add it to an online list... that kind of thing.Dare2 wrote:If you're talking server to server then would an automated client on the one server do the job?
Ah.
Could you just post (via http) to a special page on the server, and let some background scripting (via ASP or Perl, whatever) update the file?
Providing you have scripting access, that would be a darn site easier than writing an ftp client as a part of your game or app. PB has HTTP stuff to make it a few lines of code on the client side, script shouldn't be much more.
I am pretty sure I saw http examples somewhere in the downloads from the two sites above - can't recall exact files (I have a 1 kb brain handling gigs of new info, so much synaptic thrashing is going on and the index is failing ... )
Anyhow, have a good one.
Could you just post (via http) to a special page on the server, and let some background scripting (via ASP or Perl, whatever) update the file?
Providing you have scripting access, that would be a darn site easier than writing an ftp client as a part of your game or app. PB has HTTP stuff to make it a few lines of code on the client side, script shouldn't be much more.
I am pretty sure I saw http examples somewhere in the downloads from the two sites above - can't recall exact files (I have a 1 kb brain handling gigs of new info, so much synaptic thrashing is going on and the index is failing ... )
Anyhow, have a good one.
Okay, in the codesnippets zip file from http://www.purearea.net there is a folder called "internet&co".
(EDIT: Take the CodeArchive link)
That has heaps of stuff, including http downloads, ftp, etc. I bet there are some things in there that you can bend and use.
Cya.
(EDIT: Take the CodeArchive link)
That has heaps of stuff, including http downloads, ftp, etc. I bet there are some things in there that you can bend and use.
Cya.
Here is some simple code I wrote for FTP Access...
Basically wrappers for API commands but maybe the syntax makes a little more sense for beginners 
Code: Select all
Procedure.l FTPInit()
ProcedureReturn InternetOpen_("FTP",1,"","",0)
EndProcedure
Procedure.l FTPConnect(hInternet,Server.s,User.s,Password.s,Port.l)
ProcedureReturn InternetConnect_(hInternet,Server,Port,User,Password,1,0,0)
EndProcedure
Procedure.l FTPDir(hConnect.l)
hFind=FtpFindFirstFile_(hConnect,"*.*",@FTPFile.WIN32_FIND_DATA,0,0)
If hFind
Find=1
Debug PeekS(@FTPFile\cFileName)
While Find
Find=InternetFindNextFile_(hFind,@FTPFile)
If Find
Debug PeekS(@FTPFile\cFileName)
EndIf
Wend
EndIf
EndProcedure
Procedure.l FTPSetDir(hConnect.l,Dir.s)
ProcedureReturn FtpSetCurrentDirectory_(hConnect,Dir)
EndProcedure
Procedure.l FTPCreateDir(hConnect.l,Dir.s)
ProcedureReturn FTPCreateDirectory_(hConnect,Dir)
EndProcedure
Procedure.l FTPDownload(hConnect.l,Source.s,Dest.s)
ProcedureReturn FTPGetFile_(hConnect,Source,Dest,0,0,0,0)
EndProcedure
Procedure.l FTPUpload(hConnect.l,Source.s,Dest.s)
ProcedureReturn FTPPutFile_(hConnect,Source,Dest,0,0)
EndProcedure
Procedure.l FTPClose(hInternet.l)
ProcedureReturn InternetCloseHandle_(hInternet)
EndProcedure
;--------------------
hInternet=FTPInit()
If hInternet
hConnect=FTPConnect(hInternet,"ftp.reelmediaproductions.com","guest","guest",21)
If hConnect
FTPSetDir(hConnect,"test/")
FTPDir(hConnect)
FTPDownload(hConnect,"hello.txt","C:\download.txt")
FTPUpload(hConnect,"C:\Download.txt","download.txt")
FTPClose(hInternet)
EndIf
EndIf
End

-
- User
- Posts: 60
- Joined: Wed Apr 30, 2003 2:25 pm
- Location: Västerås
- Contact:
Hm, i dont personaly like the FTPClient part of InternetExplorer, and i guess it uses that API :>
When developing client/server applications for existing protocols, please consult RFC
http://www.rfc-editor.org/
And its more fun to write your own without those APIs
When developing client/server applications for existing protocols, please consult RFC
http://www.rfc-editor.org/
And its more fun to write your own without those APIs

Thanks a lot Paul, But how can i have the size of the files ?
And if you know how can i run the connection procedure in back task
And the last, How can i have the listing about the connection ?
thx 
(sorry for my english
)
And if you know how can i run the connection procedure in back task
And the last, How can i have the listing about the connection ?
Code: Select all
230 Anonymous user logged in.
331 Anonymous access allowed, send identity (e-mail name) as password.
220 ESM Microsoft FTP Service (Version 5.0).

(sorry for my english

-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
Here is how I do it when using the FTP API calls.lazy wrote:How can i have the size of the files ?
Code: Select all
Structure PB_FIND_DATA
FileAttributes.l
CreationTimeL.l
CreationTimeH.l
LastAccessTimeL.l
LastAccessTimeH.l
LastWriteTimeL.l
LastWriteTimeH.l
FileSizeHigh.l
FileSizeLow.l
OID.l
FileName.s[#MAX_PATH]
EndStructure
;---------------------------------
; Get via FTP the first item from the Host's directory.
; Here, I want all the entries, but it could be restricted to a file
; type if desired, eg. "*.EXE" to get just the executable files.
LShFindFile = FtpFindFirstFile_(File\hInternetConnect, "*.*", @PB_FIND_DATA, 0, 0)
If LShFindFile
; There was at least one entry, so interpret it.
While GetLastError_() <> #ERROR_NO_MORE_FILES And GetLastError_() <> #ERROR_FILE_NOT_FOUND
; Loads the stored file information in local specific variables
; -------------------------------------------------------------
LSFileAttributes = PeekL( @PB_FIND_DATA )
LSCreationTimeL = PeekL( @PB_FIND_DATA + 4 )
LSCreationTimeH = PeekL( @PB_FIND_DATA + 8 )
LSLastAccessTimeL = PeekL( @PB_FIND_DATA + 12 )
LSLastAccessTimeH = PeekL( @PB_FIND_DATA + 16 )
LSLastWriteTimeL = PeekL( @PB_FIND_DATA + 20 )
LSLastWriteTimeH = PeekL( @PB_FIND_DATA + 24 )
LSFileSizeHigh = PeekL( @PB_FIND_DATA + 28 )
LSFileSizeLow = PeekL( @PB_FIND_DATA + 32 )
LSOID = PeekL( @PB_FIND_DATA + 36 )
LSFileName.s = PeekS( @PB_FIND_DATA + 44 )
If #FILE_ATTRIBUTE_DIRECTORY & LSFileAttributes
; It is a Directory entry, so ignore it
Else
; It is a File entry, so get all the info
File\FileName = Trim(LSFileName) ; Get the file name
File\Bytes = (LSFileSizeLow + 1024 * LSFileSizeHigh) ; and size
File\FileSizeTotal = File\FileSizeTotal + File\Bytes ; Accum the file size
File\FilesToGet = File\FilesToGet + 1 ; Accum the file count
; Now, store the file name in our list (ListIconGadget)
AddGadgetItem(42, -1, File\FileName+Chr(10)+Str(File\Bytes))
EndIf
; And, ask for the next entry in the directory
InternetFindNextFile_(LShFindFile, @PB_FIND_DATA)
; until there are no more entries.
Wend
InternetCloseHandle_(LShFindFile)
Else
; There were no files meeting the specs to be downloaded.
FilesToGet = 0
EndIf
; ----------------------------------------------------------------
; List is built
; ----------------------------------------------------------------
AFAIK, the FTP APIs don't return this conversation. But you can easily do this using the FTP for all PB OS's thanks to Num3. See my example about this in your other post today.lazy wrote:And the last, How can i have the listing about the connection ?
Code: Select all
230 Anonymous user logged in. 331 Anonymous access allowed, send identity (e-mail name) as password. 220 ESM Microsoft FTP Service (Version 5.0).
Terry
- NoahPhense
- Addict
- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida