Subject Re: Direct copy instead of ftp
From Mervyn Bick <invalid@invalid.invalid>
Date Thu, 29 Sep 2016 15:02:40 +0200
Newsgroups dbase.getting-started

On 29-Sep-16 9:43 AM, Charlie wrote:
> Hi Ken...
>
> Due to a work load I haven't been able to do much about this but I understand what you said about the source code and I will work on that.  Also the .cc files.. They should be in the same directory?

If  the .cc files are in the working directory you can simply SET
PROCEDURE TO whatever.cc in your code.  If they are in a separate
directory you can supply the path  SET PROCEDURE TO
c:\duflp\whatever.cc.  Using a path in this scenario is, however, not a
good idea.  It is better to create a sourcecode alias and use that.  SET
PROCEDURE TO :duflp:whatever.cc.


> Possibly my objective is not in my realm of reach on this.  What I would like to do is within my own code on certain criteria, automatically ftp to our site.  I don't want to have to put in a password as I would hope there is a way of having that automatic.

I doubt if your FTP server manager will allow access without a password.
   Even anonymous users, when accepted, are usually required to enter
their email addresses as a password.

> I have this coded now so that under the certain criteria a picture is copied to a certain local directory.  Once done processing the pictures into that directory, they are manually ftp'd to our remote server.  This is not extremely time consuming or complicated.  But human error or forgetfulness could be a problem. If I could automate this it would be better.
>
> What I'm wondering am I wasting my time in trying to auto ftp?  Is this going to be a hair loss procedure for me a guy who is more or less a beginner in oodml?

If your FTP server accepts "plain" FTP (ie does not require SFTP or
FTPS) you should be able to use the FTP client built into Windows.  I
haven't used it since Windows XP but I believe it is still available in
Windows 10. Unfortunately I no longer have an account on an FTP server
to play with and most servers will not allow anonymous users to post
files so I can't try this for myself.

To automate the transfer of files using the Windows FTP client is
relatively simple.  You need to use a file object to build a script
file.  In your program the following will run the script.

set procedure to :duflp:miscapi.prg
runhidden("ftp   -s:upload_jpg.txt ftp.whatever.com > ftp.log")


The script file, upload_jpg.txt, needs to look like the following.


USER your_user_name
your_password_in_plain_text
BINARY
lcd c:\localfolderpath
cd \serverfolderpath
put 1.jpg
put 2.jpg
put 3.jpg
disconnect
quit

If the folder only holds the pictures for the current FTP session you
can use mput *.jpg instead of a separate line for each picture.  In this
case you would need to add -i (to suppress the server's request for
confirmation before each file is sent) before the -s:upload_jpg.txt in
your program.


To create the script

f = new file()
f.create('upload_jpg.txt') //will overwrite existing without asking
f.puts('USER your_user_name')
f.puts('your_password_in_plain_text')
f.puts('BINARY')
f.puts('lcd c:\localfolderpath')
f.puts('cd \serverfolderpath')
//Code here to create a separate line for each picture.
//Perhaps keep track of the pictures by saving the names in
//an array.  Loop through the array creating a line per picture.
f.puts('put 1.jpg')
//
f.pus('disconnect')
f.puts('quit')
f.close()

> btw in the form in which I placed an ftp object? on,  the properties are all null in native object.  They will not change and I don't understand that at all.

You can't change things in the Inspector but you can from a program. If
you look at the sourcecode for Ken's form you will see that he changes
properties such as HostName, UserName and Password and he executes
methods such as GetDirectory() and Connect().  Open the file in the
sourcecode editor.  Use ctrl-F to find oFTP. and step through the
program. (Include the . after oFTP in the search string otherwise you
will get hits on lines that aren't what you want.)

With testFTP.prg Ken shows how to upload all the files from a directory.
  It looks as if he has used this to copy a bunch of .html files for a
web site.  Once you have got this working you will probably need to set
the FileType property of the nativeObject to BINARY for transferring
.jpg files.  (I assume the default is ASCII which would be appropriate
for .html files.  Unfortunately dBase hasn't provided much in the way of
documentation for the bundled ActiveX components.)


Mervyn.