Запись файла на ресурс с авторизацией

Kizarek86

Well-Known Member
Lotus team
20.07.2007
863
6
#1
Нужно серверным агентом записать файл на файловый ресурс требующий авторизации.
Подскажите в какую сторону копать, файл создается с помощью NotesStream
 

TIA

:-)
Lotus team
15.05.2009
790
2
#2
Копай в сторону файлового ресурса. :( Что это, как называется, по какому протоколу работает и т.п.
 
A

allex

Гость
#3
Вот ссылочки на ресурсы

http://www.openntf.org/Projects/codebin/co...8256BDC000CC17D

http://www-10.lotus.com/ldd/46dom.nsf/0/55...e6?OpenDocument

А вот пример класса
<!--shcode--><pre><code class='vb'>'
' NetworkConnection.lss
'

Option Explicit
Option Base 0

Private Const EXTERNAL_PROCESS_STARTED = 33
Private Const NO_CONNECTION_ERR =34
Private Const SHELL_MIN_NO_FOCUS = 6 'C.f. "lsconst.lss"

Public Class NetworkConnection
'This class is used in agents that run on the server (where the server runs as an
'NT service). It gives the agent access to network shares. The class
'runs an NT batch file (which is created on the fly). This batch file
'establishes a connection using the "net use" command. The class checks
'that the command runs to completion, by looking for a temporary file
'that is created by the batch file.
'
'TODO: Use API calls instead of a batch file.
'
'The class requires the constants NO_CONNECTION_ERR to be set (to anything).
'
'Usage:
' Const USER_NAME = "AI-IS\archivereader" ' The user name
' Const PWD = "******" ' The user's password
' Const DRIVE = "\\emu\archive" ' The path to the network resource.
' ' (\\server\share)
'
' Dim connection As New NetworkConnection(DRIVE, USER_NAME, PWD)
' Call connection.connect()
'
' 'Your code goes here. (Read or write to the file etc...)
'
' Call connection.close()
'
Private drive_ As String
Private user_ As String
Private password_ As String
'TODO: Use local variable instead.
Private netUseBatchFile_ As String 'A batch file that is created on the fly

Public Sub New(drive As String, user As String, _
password As String)
drive_ = drive
user_ = user
password_ = password
End Sub

Public Sub Delete
'For now, do nothing.
End Sub

'Throws an error (NO_CONNECTION_ERR) if we can't connect.
Public Sub connect()
If Not (AddNetworkConnection(password_, user_, drive_)) Then
Error NO_CONNECTION_ERR, _
"Can't establish connection."
End If
End Sub

Public Sub close()
'Deletes a network connection and then deletes the
'batch file that was used for creating the connection.

Dim del_command As String
del_command = "cmd /c net use " & drive_ & _
" /delete"
Dim task_id As Integer
task_id% = Shell(del_command,_
SHELL_MIN_NO_FOCUS)

If (Dir$(netUseBatchFile_) <> "") Then
Kill netUseBatchFile_
End If
End Sub

Private Function AddNetworkConnection(passWord As String, _
user As String, drive As String) As Variant

netUseBatchFile_ = CreateNetUseBatchFile

Dim probe_file As String
probe_file = GetTempFile("tmp")

Dim taskId As Integer
taskId% = Shell(netUseBatchFile_ & " " & _
passWord & " " & probe_file & " " & user & " " & drive,_
SHELL_MIN_NO_FOCUS)

If (taskId = EXTERNAL_PROCESS_STARTED) Then
Dim sleep_seconds As Single
sleep_seconds = 2
Dim i As Integer
For i% = 0 To 30
If Dir$(probe_file) <> "" Then
Kill probe_file
AddNetworkConnection = True
Exit Function
Else
Sleep(sleep_seconds)
End If
Next
AddNetworkConnection = False
Exit Function
Else
AddNetworkConnection = False
Exit Function
End If

End Function

Private Function CreateNetUseBatchFile As String
' Creates a batch file for connecting to a network drive.
' TODO: We should use a Win32 API function instead.
Dim line_feed As String
line_feed = Chr$(13) & Chr$(10)

Dim batch_cmds As String
'%1 = password
'%2 = probe file
'%3 = user name
'%4 = network drive
batch_cmds = _
"@echo off " & line_feed & _
"net use %4 /user:%3 %1 " & line_feed & _
"echo apa > %2 "

Dim file_name As String
file_name = GetTempFile("bat")
Dim file_number As Integer
file_number = Freefile
Open file_name For Output As file_number

Print #file_number, batch_cmds
Close file_number

CreateNetUseBatchFile = file_name
End Function

End Class

Sub Initialize

End Sub
Private Function GetTempFile(extension As String) As String
'Creates a random and unique file name. If the random
' file name is already taken it tries again by calling it self
' recursively.

Dim temp_dir As String
temp_dir = Environ$("TEMP")

Do
Randomize
GetTempFile = temp_dir & |\| & _
"~AI" & Ltrim$(Str$(Round((Rnd()*10000),0))) & "." & extension
Loop Until Dir$(GetTempFile, 0) = ""

End Function
Sub Terminate

End Sub[/CODE]
 

DNT

Постоялец форума
Lotus team
12.10.2005
590
7
#4
Вместо NetUse лучше/проще юзать:

Dim fso As Variant
Dim network As Variant
Set fso = createobject("Scripting.FileSystemObject")
Set network = createobject("WScript.Network")
Call network.MapNetworkDrive(disk$, Path, UserName,Password) 'попытка подключения
Call fso.CopyFile (filename$, filedist$) 'копирование на сеть
Call network.RemoveNetworkDrive (disk$,True) 'отключение сет. диска
 
A

allex

Гость
#5
А ежели по различным причинам отвалится "механизм" создания объекта WScript.Network
 

Kizarek86

Well-Known Member
Lotus team
20.07.2007
863
6
#7
Dim fso As Variant
Dim network As Variant
Set fso = createobject("Scripting.FileSystemObject")
Set network = createobject("WScript.Network")
Call network.MapNetworkDrive(disk$, Path, UserName,Password) 'попытка подключения
Call fso.CopyFile (filename$, filedist$) 'копирование на сеть
Call network.RemoveNetworkDrive (disk$,True) 'отключение сет. диска
На сервере упорно падаем с ошибкой A specified logon session does not exist. It may already have been terminated.
Локаль работает
 

lmike

нет, пердело совершенство
Lotus team
27.08.2008
6 491
367
#8
а чего бы не поднять вебдав (на сервере), и работать без МС извратов?
 

DNT

Постоялец форума
Lotus team
12.10.2005
590
7
#10
погугли на возвр. ошибку. есть описание от майкрософта
 

lmike

нет, пердело совершенство
Lotus team
27.08.2008
6 491
367
#11
про webdav читаем вики:
http://en.wikipedia.org/wiki/Webdav#Microsoft_Windows

как поднять сервис на МСявой платформе - читаем их мануалы (это не должно быть сложно)
типа http://www.windowsnetworking.com/articles_...WebDAV-IIS.html

про возможную реализацию клиента (а их кучи):
http://dolzhenko.blogspot.com/2008/12/java...ile-upload.html

можно использовать типа http://jcifs.samba.org/
 

Kizarek86

Well-Known Member
Lotus team
20.07.2007
863
6
#12
Ну в общем не стал разбираться с ошибкой, сделал подключение через Net Use в cmd)
Всем большое спасибо за советы.