Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
'MESSAGE http://www.powerbasic.com/support/forums/Forum4/HTML/007538.html
'FORUM: PowerBASIC for Windows
'TOPIC: Assign ftp literal to ?
'NAME: Brad D Byrne, Member
'DATE: January 19, 2003 11:25 PM
Hey All,
'm using:
SHELL "ftp -s:C:\My_ftpTempScrpt.txt"
with My_ftpTempScrpt.txt being:
open ftp.domain.com
myusername
mypassword
ascii
literal size My_file.txt
quit
and, this returns the size of My_file.txt in the dos-prompt window...
but, how can I assign this value to a variable or copy to a file?
Thanks, Brad
------------------
Wash DC Area
Brad@ByrneWorld.com
'############################ REPLY ############################
'Clay Clear, Member
'posted January 19, 2003 11:37 PM
Brad,
'm confused as to why you're using such a method? Why do you
not use the builtin PB TCP commands, so you can control
everything? The port number for the FTP command channel is
21, and 20 for the data channel (however, conventional wisdom, and
I agree with it, says that you should instead get a data channel
port number via one of the FTP commands. I am sorry, I cannot at this
time remember what the command is. ).
------------------
clayclear2@mchsi.com
[This message has been edited by Clay Clear (edited January 19, 2003).]
'############################ REPLY ############################
'Brad D Byrne, Member
'posted January 19, 2003 11:44 PM
Hey, Clay
'm trying to control a server which doesn't support CGI's from
my host machine...so unless 'm confused, I would need to run an exe
on the server to get the size of a file located on server, using tcp...
correct?
Thanks, Brad
------------------
Wash DC Area
Brad@ByrneWorld.com
'############################ REPLY ############################
'Clay Clear, Member
'posted January 19, 2003 11:59 PM
Hmmmm, I do not know much about that kind of stuff. However, there
is an FTP command for getting a directory listing from the current
directory on the FTP site. Unfortunately, I have not done FTP stuff
for so long, I do not remember the FTP commands. Anyway, the command
I am thinking of also returns the 's size, on MOST servers.
From what 've read, directory listings from FTP sites are one of
those things that can vary from server type to server type, and maybe
with variations within the same type of server software.
My suggestion to you would be to download & read the FTP wrapper
DLL that Don Dickinson wrote. It is available in the PB 's
Files Download section, and I believe it is called "FTP.ZIP". It is
open source, and free (thanks, Don! ). By reading the source
files within the archive, you can find out how to use some of the
FTP commands. 's implementation of the data channel port is the
one I suggested in my first posting, and is a more "secure" method
than straight using port 20 for the data channel. His code also
contains functionality for retrieving the directory listing from
the current directory on the server.
Of course, if you want to keep with using your current method, then
I cannot help you, as I have never used FTP.EXE.
'm sorry that I could not be of more help.
------------------
clayclear2@mchsi.com
'############################ REPLY ############################
'Wayne Diamond, Member
'posted January 20, 2003 12:01 AM
Brad, I dont think 's any easy way, but one thing you could do is redirect the FTP output into a file (ftp.exe -s:script.txt > output.txt) and then read in the file from your PB app. Just make sure that the last line of your FTP script is "quit"
------------------
The PowerBASIC Crypto Archives - My Email - 's mine is yours...
'############################ REPLY ############################
'Brad D Byrne, Member
'posted January 20, 2003 12:05 AM
Ok, Good Idea!! Clay,
'll look at Don's code,
Thanks,
B
------------------
Wash DC Area
Brad@ByrneWorld.com
'############################ REPLY ############################
'Brad D Byrne, Member
'posted January 20, 2003 01:21 AM
Wayne, I missed your post somehow???...
anyway I tried that w/o the .exe part...'ll give it a shot...
Thanks,
Brad
------------------
Wash DC Area
Brad@ByrneWorld.com
'############################ REPLY ############################
'Wayne Diamond, Member
'posted January 20, 2003 01:36 AM
what do you mean missed it? 's still there
't matter if you declare it as ftp or ftp.exe as long as Windows looks in the right path
------------------
The PowerBASIC Crypto Archives - My Email - 's mine is yours...
'############################ REPLY ############################
'Brad D Byrne, Member
'posted January 20, 2003 01:45 AM
Wayne, it snuck in there... I 't know what kind of tricks your
doing with your crypto-ology??? but it 't there when I posted???
anyway, getting real tired...'s 4:50 am and I got to go to work at 7:30
so better try the code tomorrow...
cya,
Brad
------------------
Wash DC Area
Brad@ByrneWorld.com
'############################ REPLY ############################
'Wayne Diamond, Member
'posted January 20, 2003 02:16 AM
Its a new steganographical technique im working on -- concealing posts by posting in plaintext
------------------
The PowerBASIC Crypto Archives - My Email - 's mine is yours...
'############################ REPLY ############################
'Brad D Byrne, Member
'posted January 20, 2003 04:29 PM
Arrrrrrrrggggghhhhh!!!
well, I 't seen to get a command like;
ftp.exe -s:script.txt > output.txt
to work in any way, ie. as a file script or as a direct ftp command
like: ftp script.txt > output.txt ...(after properly logged on)
I keep getting "no such file" error msg... even when 've pre included
the file.... and when I used a full path?????
also 've looked over Don's FTP functions again... and no ref. to similar...
any ideas, anyone?
Thx, Brad
------------------
Wash DC Area
Brad@ByrneWorld.com
'############################ REPLY ############################
'Lance Edmonds, Member
'posted January 20, 2003 05:59 PM
You can programnmatically get the size of a remote file with InternetSetFilePointer() and the %FILE_END flag... see http://www.powerbasic.com/support/forums/Forum7/HTML/001251.html
------------------
Lance
PowerBASIC Support
support@powerbasic.com
'############################ REPLY ############################
'Brad D Byrne, Member
'posted January 20, 2003 06:18 PM
Thanks, Lance
've been reluctant to go the Wininet route... let me first see if
I can tcp it...I need the education anyway...
Brad
------------------
Wash DC Area
Brad@ByrneWorld.com
'############################ REPLY ############################
'Wayne Diamond, Member
'posted January 20, 2003 06:42 PM
Brad, it (ftp.exe > file redirection) worked fine under Win2K, maybe 's an OS thing ...
------------------
The PowerBASIC Crypto Archives - My Email - 's mine is yours...
'############################ REPLY ############################
'Joe Byrne, Member
'posted January 20, 2003 06:42 PM
Brad,
The FTP protocol provides for a server sided directory list and/or
a specified file list. If you use 's FTP routines, look at the
ftpGetFileList function. It will return a string with the
specific info for the file name specified. You will need to first
issue a CHDIR (change directory) to the proper directory on the server
then issue the ftpGetFileList function. You might also have to parse
the results yourself as different FTP servers can use different formats.
've written a number of FTP related programs, and while Don's collection
is top notch, 've found Marshalsoft's to be a bit more compatible with
a variety of servers.
--Joe
------------------
Joe Byrne
PBStuff@ByrneWorld.com
'############################ REPLY ############################
'Brad D Byrne, Member
'posted January 21, 2003 04:53 AM
'MESSAGE http://www.powerbasic.com/support/forums/Forum4/HTML/007538-2.html
Wayne, yes that makes sense, 'm running '98
Joe, agree ftp, http, telnet etc. runs on top of tcp, so must be able
to call ftp commands from tcp....soon
Brad
------------------
Wash DC Area
Brad@ByrneWorld.com
'############################ REPLY ############################
'Michael Charnock, unregistered
'posted January 21, 2003 05:51 AM
Brad
This should do what you need.
There will be a user unfriendly pause after you click to connect where nothing appears to happen so you may need some form of feedback to the user. Just wait a few seconds
Mike
#COMPILE EXE
FUNCTION PBMAIN() AS LONG
LOCAL sBuffer AS STRING
LOCAL sSite AS STRING
LOCAL sFile AS STRING
LOCAL sUserName AS STRING
LOCAL sPassword AS STRING
LOCAL hTCP AS LONG
sSite = "ftp.yoursite.com"
sFile = "/www/htdocs/index.htm"
sUserName = "username"
sPassword = "password"
MSGBOX "Click OK to connect. Initial connection may take a few seconds - be patient"
' Connecting...
TCP OPEN "ftp" AT sSite AS hTCP TIMEOUT 60000
' Could we connect to site?
IF ERR THEN
BEEP
EXIT FUNCTION
END IF
' Get the HELLO message
TCP RECV hTCP, 4096, sBuffer
MSGBOX sBuffer
' Send the USER message
TCP PRINT hTCP, "USER " & sUserName
' Get the USER OK, PASSWORD NEEDED message
TCP RECV hTCP, 4096, sBuffer
MSGBOX sBuffer
' Send the PASS message
TCP PRINT hTCP, "PASS " & sPassword
' Get the LOGGED IN message
TCP RECV hTCP, 4096, sBuffer
MSGBOX sBuffer
' Send the SIZE message
TCP PRINT hTCP, "SIZE " & sFile
' Get the RESULT of the SIZE message
TCP RECV hTCP, 4096, sBuffer
' will return a message in the format XXX YYY where XXX
' is the status code (probably 213) and YYY is the size of the file
MSGBOX "File size is " & REMAIN$(sBuffer," ")
' Send the QUIT message
TCP PRINT hTCP, "QUIT"
TCP RECV hTCP, 4096, sBuffer
MSGBOX sBuffer
' Close the TCP/IP port...
TCP CLOSE hTCP
END FUNCTION
------------------
[This message has been edited by Michael Charnock (edited January 22, 2003).]
'############################ REPLY ############################
'Brad D Byrne, Member
'posted January 21, 2003 06:18 AM
Thanks, Much!! Michael
I got to get to work...'ll run it tonight...
Brad
------------------
Wash DC Area
Brad@ByrneWorld.com
'############################ REPLY ############################
'Brad D Byrne, Member
'posted January 21, 2003 07:41 PM
Michael
Your examples have been extremely helpful!!! Thanks, Much
interesting though... when I try to get file size w/ the tcp code...
it returns; "permission denied", how-ever, I could get the file size
with the ftp code, I guess the sever is configured for minimum tcp transmission..
anyway, I guess I really 't need the file size... but this has taught
me much... Thanks, Again...(any other tricks? )
Brad
HEY!!!! HAPPY HAPPY... had path wrong and now it works like a charm!!!!
------------------
Wash DC Area
Brad@ByrneWorld.com
[This message has been edited by Brad D Byrne (edited January 21, 2003).]
'############################ REPLY ############################
'Michael Charnock, unregistered
'posted January 22, 2003 12:31 AM
No tricks - just be aware that when talking to an ftp server this method only works for commands that return the answer directly on the control connection. If you ask for a directory listing, for example, this will require a new connection to be established for the data, in very much the same way as a file transfer.
You can do things like "cd", "pwd", "mkdir", "delete", "rename", "size"; but not "ls", "get", "put" etc
------------------
'############################ REPLY ############################
'Brad D Byrne, Member
'posted January 22, 2003 04:49 AM
Yes, Michael
when reviewing 's code... the additional processing becomes evident...
your examples, saved many hrs...trying to figure out what 's wrapper
is doing....
Thx, Again, Again, Again
Brad
------------------
Wash DC Area
Brad@ByrneWorld.com
'gbs_01305
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm