Home All Groups Group Topic Archive Search About

CopyFile method not working

Author
1 Sep 2010 6:02 PM
Dipesh_Sharma
Hi,
I am using following code to copy a file or folder from computer A to
computer B.

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile(sFile, sPathDest, True)

now problem here is that, if i pass "IP ADDRESS" of my source computer than
it is able to copy files & folders but if i am passing "COMPUTER NAME" than
it gave a strange error: "Method '   ' of object '  ' failed"
its very strange error, and i am not able to fix it.
dest.:"\\192.168.2.10\test\copy.txt" is working fine but
"\\computer00top\test\copy.txt" is not working. Thing is that, i am able to
ping that computer name and able to copy file from there manually, by typing
path in explorer.
Any help will be appreciated.

Thanks,
Dipesh

Author
1 Sep 2010 7:43 PM
MikeD
Show quote Hide quote
"Dipesh_Sharma" <DipeshSha***@discussions.microsoft.com> wrote in message
news:DD3C6331-B915-4B5C-A1F6-E378CB8D2A82@microsoft.com...
> Hi,
> I am using following code to copy a file or folder from computer A to
> computer B.
>
> Dim fso
> Set fso = CreateObject("Scripting.FileSystemObject")
> fso.CopyFile(sFile, sPathDest, True)
>
> now problem here is that, if i pass "IP ADDRESS" of my source computer
> than
> it is able to copy files & folders but if i am passing "COMPUTER NAME"
> than
> it gave a strange error: "Method '   ' of object '  ' failed"
> its very strange error, and i am not able to fix it.
> dest.:"\\192.168.2.10\test\copy.txt" is working fine but
> "\\computer00top\test\copy.txt" is not working. Thing is that, i am able
> to
> ping that computer name and able to copy file from there manually, by
> typing
> path in explorer.
> Any help will be appreciated.
>


Don't use the FSO for this.  Use VB's own FileCopy statement.

--
Mike
Author
2 Sep 2010 1:01 PM
Phill W.
On 01/09/2010 19:02, Dipesh_Sharma wrote:

> Hi,
> I am using following code to copy a file or folder from computer A to
> computer B.
>
> Dim fso
> Set fso = CreateObject("Scripting.FileSystemObject")
> fso.CopyFile(sFile, sPathDest, True)

Oh Dear.

/*Assuming*/ that this is VB, then

FileCopy sFile, sPathDest

is all you need (OK; with a /bit/ of error handling around it).


> dest.:"\\192.168.2.10\test\copy.txt" is working fine but
> "\\computer00top\test\copy.txt" is not working.

Odd.  If anything I'd expect the name to work and not the IPAddress.


> Thing is that, i am able to ping that computer name and able to copy
> file from there manually, by typingpath in explorer.

How is your program running?  A standard VB exe that you run from a
shortcut?  Or something else?  Like ASP?

Not every process can "see" the network - web applications and Windows
Services are two that spring to mind; neither of these, by default, can
do anything with the network (to them, it just doesn't exist).  But a
"normal" VB program that you run should be able to do everything that
/you/ can do.

Regards,
    Phill  W.
Author
2 Sep 2010 7:18 PM
Jeff Johnson
"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-k> wrote in message
news:i5o76v$tfj$1@news.eternal-september.org...

>> dest.:"\\192.168.2.10\test\copy.txt" is working fine but
>> "\\computer00top\test\copy.txt" is not working.
>
> Odd.  If anything I'd expect the name to work and not the IPAddress.

No, from my experience, IP addresses in UNC paths are far more reliable than
names if you've got screwy DNS going on. I often have to use IP addresses at
home vs. computer names. Stupid router....
Author
2 Sep 2010 7:54 PM
Mike Williams
"Jeff Johnson" <i.get@enough.spam> wrote in message
news:i5otah$ebi$1@news.eternal-september.org...

> from my experience, IP addresses in UNC paths are far more
> reliable than names if you've got screwy DNS going on. I often
> have to use IP addresses at home vs. computer names.
> Stupid router....

Have you checked your hosts file?

Mike
Author
3 Sep 2010 2:26 PM
Jeff Johnson
"Mike Williams" <M***@WhiskyAndCoke.com> wrote in message
news:i5ovdn$1v5$1@speranza.aioe.org...

>> from my experience, IP addresses in UNC paths are far more
>> reliable than names if you've got screwy DNS going on. I often
>> have to use IP addresses at home vs. computer names.
>> Stupid router....
>
> Have you checked your hosts file?

I guess I could put the machines with the fixed IPs in my hosts files, but
that doesn't help me with the machines that use DHCP. Sometimes I can hit
them by name, sometimes not.

Not the end of the world, just frustrating.
Author
4 Sep 2010 12:08 AM
Mike S
On 9/3/2010 7:26 AM, Jeff Johnson wrote:
Show quoteHide quote
> "Mike Williams"<M***@WhiskyAndCoke.com>  wrote in message
> news:i5ovdn$1v5$1@speranza.aioe.org...
>
>>> from my experience, IP addresses in UNC paths are far more
>>> reliable than names if you've got screwy DNS going on. I often
>>> have to use IP addresses at home vs. computer names.
>>> Stupid router....
>>
>> Have you checked your hosts file?
>
> I guess I could put the machines with the fixed IPs in my hosts files, but
> that doesn't help me with the machines that use DHCP. Sometimes I can hit
> them by name, sometimes not.
>
> Not the end of the world, just frustrating.

Is using XCopy or Robocopy an option?

http://www.dslreports.com/forum/r19676024-Xcopy-and-UNC-path-names
xcopy \\server\data\*.* \\backup\data
/y at the end if you want it to overwrite
/s at the end if you want subdirectories copied as well

http://ss64.com/nt/robocopy.html
ROBOCOPY will accept UNC pathnames including UNC pathnames over 256
characters long.

http://www.lordgoogle.com/downloads/robocopy/robocopy.doc
Finally, as drive mappings can be changed by users, it is generally best
to use UNC names for source and destination directories in scheduled
Robocopy jobs, as these explicity specify file locations, and are more
reliable. I.e. rather than scheduling a command of the form :
ROBOCOPY X:\source Y:\dest ...
for increased reliability, you should use commands of the form :
ROBOCOPY \\server1\share1\source \\server2\share2\dest ...
Author
7 Sep 2010 2:04 PM
Jeff Johnson
Show quote Hide quote
"Mike S" <ms***@yahoo.com> wrote in message
news:i5s2ll$1h6$1@news.eternal-september.org...

>>>> from my experience, IP addresses in UNC paths are far more
>>>> reliable than names if you've got screwy DNS going on. I often
>>>> have to use IP addresses at home vs. computer names.
>>>> Stupid router....
>>>
>>> Have you checked your hosts file?
>>
>> I guess I could put the machines with the fixed IPs in my hosts files,
>> but
>> that doesn't help me with the machines that use DHCP. Sometimes I can hit
>> them by name, sometimes not.
>>
>> Not the end of the world, just frustrating.
>
> Is using XCopy or Robocopy an option?

Not really, because usually I just want to browse the share in an Explorer
window.